Skip to content

Commit 5a9c002

Browse files
committed
comments
AdaptorV1 data.Store metadataupdates.Store TransformFunc
1 parent a5de2d4 commit 5a9c002

File tree

8 files changed

+33
-11
lines changed

8 files changed

+33
-11
lines changed

backend/cmd/eth1indexer/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func Run() {
192192
}
193193

194194
indexer := executionlayer.NewIndexer(
195-
executionlayer.NewBigtableAdaptor(
195+
executionlayer.NewAdaptorV1(
196196
data.NewStore(database.Wrap(bigtable, data.Table)),
197197
metadataupdates.NewStore(database.Wrap(bigtable, metadataupdates.Table), cache),
198198
),

backend/cmd/misc/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,7 @@ func indexOldEth1Blocks(startBlock uint64, endBlock uint64, batchSize uint64, co
16321632
return
16331633
}
16341634
indexer := executionlayer.NewIndexer(
1635-
executionlayer.NewBigtableAdaptor(
1635+
executionlayer.NewAdaptorV1(
16361636
data.NewStore(database.Wrap(bigtable, data.Table)),
16371637
metadataupdates.NewStore(database.Wrap(bigtable, metadataupdates.Table), cache),
16381638
),

backend/pkg/commons/db2/data/data.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/gobitfly/beaconchain/pkg/commons/types"
1717
)
1818

19+
// Store encapsulate all the interaction with the data store which contains all the indexed objects
1920
type Store struct {
2021
db database.Database
2122
}
@@ -116,6 +117,10 @@ func (store Store) AddIndexedBlock(block IndexedBlock) ([]string, error) {
116117
return maps.Keys(updates), nil
117118
}
118119

120+
// Get allows to retrieve Transactions and ERC20 Transfers from the Store
121+
// some Option can be applied to add filter on the search
122+
// This is a WIP functionality, used only in tests for now
123+
// but it will the base for account dashboard functionalities
119124
func (store Store) Get(chainIDs []string, addresses []common.Address, prefixes map[string]map[string]string, limit int64, opts ...Option) ([]*Interaction, map[string]map[string]string, error) {
120125
sources := map[formatType]unMarshalInteraction{
121126
typeTx: unMarshalTx,

backend/pkg/commons/db2/data/tables.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package data
22

33
const Table = "data"
44

5+
// Schema is a map containing the bigtable table and the family
56
var Schema = map[string][]string{
67
Table: {
78
defaultFamily,

backend/pkg/commons/db2/metadataupdates/store.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import (
99
"github.com/gobitfly/beaconchain/pkg/commons/types"
1010
)
1111

12+
// Store encapsulate all the interaction with the metadata_updates store, it contains:
13+
// - the mutation for a block (in case of reorg)
14+
// - the balance update keys (balance to update, record is deleted once balance is updated)
15+
// - the contract keys (to track if an address is a contract)
16+
//
17+
// also have caching to prevent putting multiple balance to update for the same address / token pair
18+
// clearing the cache is the responsibility of the caller for now
1219
type Store struct {
1320
db database.Database
1421
cache Cache
@@ -37,6 +44,8 @@ func (store Store) NewBatch() *database.Batch {
3744
return database.NewBatch(store.db)
3845
}
3946

47+
// AddIndexedBlock extracts all the data to save from an IndexedBlock
48+
// Moreover it takes a list of keys as param to save the different keys update in the data.Store in case of a reorg
4049
func (store Store) AddIndexedBlock(number uint64, hash []byte, block IndexedBlock, keys []string) error {
4150
updates := make(map[string][]database.Item)
4251
if len(keys) > 0 {

backend/pkg/executionlayer/adaptor.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,22 @@ type IndexedBlock struct {
2121
Contracts []metadataupdates.ContractUpdateWithAddress
2222
}
2323

24-
func NewBigtableAdaptor(data data.Store, metadataUpdates metadataupdates.Store) BigTableAdaptor {
25-
return BigTableAdaptor{
24+
// AdaptorV1 represents the current storage organisation
25+
// it consists of a data store where indexed object are saved
26+
// and a metadataUpdates store where balances and some other data are saved
27+
type AdaptorV1 struct {
28+
data data.Store
29+
metadataUpdates metadataupdates.Store
30+
}
31+
32+
func NewAdaptorV1(data data.Store, metadataUpdates metadataupdates.Store) AdaptorV1 {
33+
return AdaptorV1{
2634
data: data,
2735
metadataUpdates: metadataUpdates,
2836
}
2937
}
3038

31-
type BigTableAdaptor struct {
32-
data data.Store
33-
metadataUpdates metadataupdates.Store
34-
}
35-
36-
func (adaptor BigTableAdaptor) Save(blockNumber uint64, hash []byte, block IndexedBlock) error {
39+
func (adaptor AdaptorV1) Save(blockNumber uint64, hash []byte, block IndexedBlock) error {
3740
keys, err := adaptor.data.AddIndexedBlock(data.IndexedBlock{
3841
ChainID: block.ChainID,
3942
Block: block.Block,

backend/pkg/executionlayer/indexer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func TestIndexerWithBigTable(t *testing.T) {
139139
defer func() { _ = metadataBigtable.Clear() }()
140140

141141
indexer := NewIndexer(
142-
NewBigtableAdaptor(
142+
NewAdaptorV1(
143143
data.NewStore(database.Wrap(dataBigtable, data.Table)),
144144
metadataupdates.NewStore(database.Wrap(metadataBigtable, metadataupdates.Table), metadataupdates.NoopCache{}),
145145
),

backend/pkg/executionlayer/transformer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import (
2323
"github.com/gobitfly/beaconchain/pkg/commons/types"
2424
)
2525

26+
// TransformFunc describes a function that will index a specific object from the types.Eth1Block
27+
// example: transaction, ERC20 transfer, block, ...
28+
// It will put the indexed result into the res *IndexedBlock param
29+
// This way all transform functions have the same signature
2630
type TransformFunc func(chainID string, block *types.Eth1Block, res *IndexedBlock) error
2731

2832
var Transformers = map[string]TransformFunc{

0 commit comments

Comments
 (0)