Updated go.sum and go.mod for snapshots (#8664)

This commit is contained in:
Giulio rebuffo 2023-11-06 23:39:44 +01:00 committed by GitHub
parent 4b580dcc2f
commit e08b031f74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 85 additions and 6 deletions

View File

@ -94,6 +94,38 @@ func MarkRootCanonical(ctx context.Context, tx kv.RwTx, slot uint64, blockRoot l
return tx.Put(kv.CanonicalBlockRoots, base_encoding.Encode64(slot), blockRoot[:])
}
func WriteExecutionBlockNumber(tx kv.RwTx, blockRoot libcommon.Hash, blockNumber uint64) error {
return tx.Put(kv.BlockRootToBlockNumber, blockRoot[:], base_encoding.Encode64(blockNumber))
}
func WriteExecutionBlockHash(tx kv.RwTx, blockRoot, blockHash libcommon.Hash) error {
return tx.Put(kv.BlockRootToBlockHash, blockRoot[:], blockHash[:])
}
func ReadExecutionBlockNumber(tx kv.Tx, blockRoot libcommon.Hash) (*uint64, error) {
val, err := tx.GetOne(kv.BlockRootToBlockNumber, blockRoot[:])
if err != nil {
return nil, err
}
if len(val) == 0 {
return nil, nil
}
ret := new(uint64)
*ret = base_encoding.Decode64(val)
return ret, nil
}
func ReadExecutionBlockHash(tx kv.Tx, blockRoot libcommon.Hash) (libcommon.Hash, error) {
val, err := tx.GetOne(kv.BlockRootToBlockHash, blockRoot[:])
if err != nil {
return libcommon.Hash{}, err
}
if len(val) == 0 {
return libcommon.Hash{}, nil
}
return libcommon.BytesToHash(val), nil
}
func WriteBeaconBlockHeader(ctx context.Context, tx kv.RwTx, signedHeader *cltypes.SignedBeaconBlockHeader) error {
headersBytes, err := signedHeader.EncodeSSZ(nil)
if err != nil {

View File

@ -140,3 +140,35 @@ func TestReadBeaconBlockHeader(t *testing.T) {
require.Equal(t, headerRoot, blockRoot)
}
func TestWriteExecutionBlockNumber(t *testing.T) {
db := setupTestDB(t)
defer db.Close()
tx, _ := db.BeginRw(context.Background())
defer tx.Rollback()
tHash := libcommon.HexToHash("0x2")
require.NoError(t, WriteExecutionBlockNumber(tx, tHash, 1))
require.NoError(t, WriteExecutionBlockNumber(tx, tHash, 2))
require.NoError(t, WriteExecutionBlockNumber(tx, tHash, 3))
// Try to retrieve the block's slot by its blockRoot and verify
blockNumber, err := ReadExecutionBlockNumber(tx, tHash)
require.NoError(t, err)
require.Equal(t, uint64(3), *blockNumber)
}
func TestWriteExecutionBlockHash(t *testing.T) {
db := setupTestDB(t)
defer db.Close()
tx, _ := db.BeginRw(context.Background())
defer tx.Rollback()
tHash := libcommon.HexToHash("0x2")
tHash2 := libcommon.HexToHash("0x3")
require.NoError(t, WriteExecutionBlockHash(tx, tHash, tHash2))
// Try to retrieve the block's slot by its blockRoot and verify
tHash3, err := ReadExecutionBlockHash(tx, tHash)
require.NoError(t, err)
require.Equal(t, tHash2, tHash3)
}

View File

@ -145,6 +145,15 @@ func (b beaconChainDatabaseFilesystem) WriteBlock(ctx context.Context, tx kv.RwT
if err != nil {
return err
}
if block.Version() >= clparams.BellatrixVersion {
if err := beacon_indicies.WriteExecutionBlockNumber(tx, blockRoot, block.Block.Body.ExecutionPayload.BlockNumber); err != nil {
return err
}
if err := beacon_indicies.WriteExecutionBlockHash(tx, blockRoot, block.Block.Body.ExecutionPayload.BlockHash); err != nil {
return err
}
}
if err := beacon_indicies.WriteBeaconBlockHeaderAndIndicies(ctx, tx, &cltypes.SignedBeaconBlockHeader{
Signature: block.Signature,
Header: &cltypes.BeaconBlockHeader{

View File

@ -4,7 +4,7 @@ go 1.20
require (
github.com/erigontech/mdbx-go v0.35.2-0.20231101074031-9f999220e9ed
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231106151827-2653fe9782b2
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231106204511-f1e556dd5c50
github.com/ledgerwatch/interfaces v0.0.0-20231031050643-c86352e41520
github.com/ledgerwatch/log/v3 v3.9.0
github.com/ledgerwatch/secp256k1 v1.0.0

View File

@ -291,8 +291,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231106151827-2653fe9782b2 h1:2av0zql2zwx8PL/mZWhjsuWOpHbDMK2tsiH003KriXs=
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231106151827-2653fe9782b2/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231106204511-f1e556dd5c50 h1:RECb+fAC9doD1EhVxK2/b20JeLCAumLDjnysSQ3kWfs=
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231106204511-f1e556dd5c50/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/interfaces v0.0.0-20231031050643-c86352e41520 h1:j/PRJWbPrbk8wpVjU77SWS8xJ/N+dcxPs1relNSolUs=
github.com/ledgerwatch/interfaces v0.0.0-20231031050643-c86352e41520/go.mod h1:ugQv1QllJzBny3cKZKxUrSnykkjkBgm27eQM6dnGAcc=
github.com/ledgerwatch/log/v3 v3.9.0 h1:iDwrXe0PVwBC68Dd94YSsHbMgQ3ufsgjzXtFNFVZFRk=

View File

@ -438,6 +438,10 @@ const (
// [Block Root] => [State Root]
BlockRootToStateRoot = "BlockRootToStateRoot"
StateRootToBlockRoot = "StateRootToBlockRoot"
BlockRootToBlockNumber = "BlockRootToBlockNumber"
BlockRootToBlockHash = "BlockRootToBlockHash"
// [Block Root] => [Parent Root]
BlockRootToParentRoot = "BlockRootToParentRoot"
@ -608,6 +612,8 @@ var ChaindataTables = []string{
Attestetations,
LightClient,
LightClientUpdates,
BlockRootToBlockHash,
BlockRootToBlockNumber,
}
const (

2
go.mod
View File

@ -186,7 +186,7 @@ require (
github.com/koron/go-ssdp v0.0.4 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231106151827-2653fe9782b2 // indirect
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231106204511-f1e556dd5c50 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-cidranger v1.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect

4
go.sum
View File

@ -539,8 +539,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231106151827-2653fe9782b2 h1:2av0zql2zwx8PL/mZWhjsuWOpHbDMK2tsiH003KriXs=
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231106151827-2653fe9782b2/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231106204511-f1e556dd5c50 h1:RECb+fAC9doD1EhVxK2/b20JeLCAumLDjnysSQ3kWfs=
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20231106204511-f1e556dd5c50/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/log/v3 v3.9.0 h1:iDwrXe0PVwBC68Dd94YSsHbMgQ3ufsgjzXtFNFVZFRk=
github.com/ledgerwatch/log/v3 v3.9.0/go.mod h1:EiAY6upmI/6LkNhOVxb4eVsmsP11HZCnZ3PlJMjYiqE=
github.com/ledgerwatch/secp256k1 v1.0.0 h1:Usvz87YoTG0uePIV8woOof5cQnLXGYa162rFf3YnwaQ=