From 8ee52e1ca30e6a17b18797dc28dfaaa2023685f3 Mon Sep 17 00:00:00 2001 From: Dmitrii Skopintsev Date: Wed, 25 Jun 2025 15:02:41 +0200 Subject: [PATCH] [cache] BlockAccessor with caching separate from StateAccessor --- nil/internal/collate/block_listener.go | 41 ++- nil/internal/collate/proposer.go | 10 +- nil/internal/collate/validator.go | 8 +- nil/internal/execution/block_accessors.go | 284 ++++++++++++++++++ nil/internal/execution/block_cache.go | 8 +- nil/internal/execution/block_generator.go | 4 +- .../execution/execution_state_test.go | 8 +- nil/internal/execution/state.go | 23 +- nil/internal/execution/testaide.go | 6 +- nil/services/nilservice/config.go | 4 +- nil/services/nilservice/service.go | 4 +- .../rpc/rawapi/internal/local_call.go | 4 +- .../prover/tracer/traces_collector.go | 8 +- 13 files changed, 346 insertions(+), 66 deletions(-) create mode 100644 nil/internal/execution/block_accessors.go diff --git a/nil/internal/collate/block_listener.go b/nil/internal/collate/block_listener.go index 06091fe68..6d4f46274 100644 --- a/nil/internal/collate/block_listener.go +++ b/nil/internal/collate/block_listener.go @@ -175,6 +175,22 @@ func unmarshalBlock(pbBlock *pb.RawFullBlock) (*types.BlockWithExtractedData, er return raw.DecodeBytes() } +type blockByNumberCache struct { + blockByHash *execution.BlockByHashAccessor + blockHashByNumber *execution.BlockHashByNumberAccessor +} + +func (b blockByNumberCache) Get( + tx db.RoTx, shardId types.ShardId, num types.BlockNumber, +) (*types.RawBlockWithExtractedData, error) { + hash, err := b.blockHashByNumber.Get(tx, shardId, num) + if err != nil { + return nil, err + } + + return b.blockByHash.Get(tx, shardId, hash) +} + func SetBlockRequestHandler( ctx context.Context, networkManager network.Manager, shardId types.ShardId, database db.DB, logger logging.Logger, ) { @@ -183,8 +199,10 @@ func SetBlockRequestHandler( return } - // Sharing accessor between all handlers enables caching. - accessor := execution.NewStateAccessor(128, 0) + accessor := &blockByNumberCache{ + blockByHash: execution.NewBlockByHashAccessor(128), + blockHashByNumber: execution.NewBlockHashByNumberAccessor(), + } handler := func(s network.Stream) { if err := s.SetDeadline(time.Now().Add(requestTimeout)); err != nil { return @@ -212,15 +230,8 @@ func SetBlockRequestHandler( } defer tx.Rollback() - acc := accessor.RawAccess(tx, shardId). - GetBlock(). - WithOutTransactions(). - WithInTransactions(). - WithChildBlocks(). - WithConfig() - for id := blockReq.GetId(); ; id++ { - resp, err := acc.ByNumber(types.BlockNumber(id)) + resp, err := accessor.Get(tx, shardId, types.BlockNumber(id)) if err != nil { if !errors.Is(err, db.ErrKeyNotFound) { logError(logger, err, "DB error") @@ -229,11 +240,11 @@ func SetBlockRequestHandler( } b := &pb.RawFullBlock{ - BlockBytes: resp.Block(), - OutTransactionsBytes: resp.OutTransactions(), - InTransactionsBytes: resp.InTransactions(), - ChildBlocks: pb.PackHashes(resp.ChildBlocks()), - Config: resp.Config(), + BlockBytes: resp.Block, + OutTransactionsBytes: resp.OutTransactions, + InTransactionsBytes: resp.InTransactions, + ChildBlocks: pb.PackHashes(resp.ChildBlocks), + Config: resp.Config, } if err := writeBlockToStream(s, b); err != nil { diff --git a/nil/internal/collate/proposer.go b/nil/internal/collate/proposer.go index c008156db..6ca18ae89 100644 --- a/nil/internal/collate/proposer.go +++ b/nil/internal/collate/proposer.go @@ -73,11 +73,10 @@ func (p *proposer) GenerateProposal(ctx context.Context, txFabric db.DB) (*execu if err != nil { return nil, fmt.Errorf("failed to fetch previous block: %w", err) } - data, err := p.params.StateAccessor.Access(tx, p.params.ShardId).GetBlock().ByHash(prevBlockHash) + prevBlock, err := p.params.BlockAccessor.GetByHash(tx, p.params.ShardId, prevBlockHash) if err != nil { return nil, err } - prevBlock := data.Block() if prevBlock.PatchLevel > validatorPatchLevel { return nil, fmt.Errorf( @@ -94,7 +93,7 @@ func (p *proposer) GenerateProposal(ctx context.Context, txFabric db.DB) (*execu p.executionState, err = execution.NewExecutionState(tx, p.params.ShardId, execution.StateParams{ Block: prevBlock, ConfigAccessor: configAccessor, - StateAccessor: p.params.StateAccessor, + BlockAccessor: p.params.BlockAccessor, FeeCalculator: p.params.FeeCalculator, Mode: execution.ModeProposal, }) @@ -381,17 +380,14 @@ func (p *proposer) handleTransactionsFromNeighbors(tx db.RoTx) error { neighbor := &state.Neighbors[position] nextTx := p.executionState.InTxCounts[neighborId] - shardAccessor := p.params.StateAccessor.Access(tx, neighborId) - for checkLimits() { - data, err := shardAccessor.GetBlock().ByNumber(neighbor.BlockNumber) + block, err := p.params.BlockAccessor.GetByNumber(tx, neighborId, neighbor.BlockNumber) if errors.Is(err, db.ErrKeyNotFound) { break } if err != nil { return err } - block := data.Block() outTxnTrie := execution.NewDbTransactionTrieReader(tx, neighborId) if err := outTxnTrie.SetRootHash(block.OutTransactionsRoot); err != nil { diff --git a/nil/internal/collate/validator.go b/nil/internal/collate/validator.go index 62443131f..860beaa0d 100644 --- a/nil/internal/collate/validator.go +++ b/nil/internal/collate/validator.go @@ -112,11 +112,11 @@ func (s *Validator) getLastBlockUnlocked(ctx context.Context) (*types.Block, com return nil, common.EmptyHash, err } - block, err := s.params.StateAccessor.Access(tx, s.params.ShardId).GetBlock().ByHash(hash) + block, err := s.params.BlockAccessor.GetByHash(tx, s.params.ShardId, hash) if err != nil { return nil, common.EmptyHash, err } - return block.Block(), hash, nil + return block, hash, nil } func (s *Validator) GetLastBlock(ctx context.Context) (*types.Block, common.Hash, error) { @@ -140,11 +140,11 @@ func (s *Validator) getBlock(ctx context.Context, hash common.Hash) (*types.Bloc } defer tx.Rollback() - block, err := s.params.StateAccessor.Access(tx, s.params.ShardId).GetBlock().ByHash(hash) + block, err := s.params.BlockAccessor.GetByHash(tx, s.params.ShardId, hash) if err != nil { return nil, err } - return block.Block(), nil + return block, nil } func (s *Validator) TxPool() TxnPool { diff --git a/nil/internal/execution/block_accessors.go b/nil/internal/execution/block_accessors.go new file mode 100644 index 000000000..39a4b57d8 --- /dev/null +++ b/nil/internal/execution/block_accessors.go @@ -0,0 +1,284 @@ +package execution + +import ( + "errors" + "fmt" + + "github.com/NilFoundation/nil/nil/common" + "github.com/NilFoundation/nil/nil/common/assert" + "github.com/NilFoundation/nil/nil/common/check" + "github.com/NilFoundation/nil/nil/internal/db" + "github.com/NilFoundation/nil/nil/internal/mpt" + "github.com/NilFoundation/nil/nil/internal/types" + lru "github.com/hashicorp/golang-lru/v2" +) + +type BlockAccessor struct { + headers *BlockHeaderByHashAccessor + hashByNumber *BlockHashByNumberAccessor +} + +func NewBlockAccessor(blocksLRUSize int) *BlockAccessor { + return &BlockAccessor{ + headers: NewBlockHeaderByHashAccessor(blocksLRUSize), + hashByNumber: NewBlockHashByNumberAccessor(), + } +} + +func (s BlockAccessor) GetByHash(tx db.RoTx, shardId types.ShardId, hash common.Hash) (*types.Block, error) { + return s.headers.Get(tx, shardId, hash) +} + +func (s BlockAccessor) GetByNumber(tx db.RoTx, shardId types.ShardId, num types.BlockNumber) (*types.Block, error) { + hash, err := s.hashByNumber.Get(tx, shardId, num) + if err != nil { + return nil, err + } + + return s.headers.Get(tx, shardId, hash) +} + +type headerWithRaw struct { + block *types.Block + raw []byte +} + +type BlockHeaderByHashAccessor struct { + cache *lru.Cache[common.Hash, headerWithRaw] +} + +func NewBlockHeaderByHashAccessor(blocksLRUSize int) *BlockHeaderByHashAccessor { + cache, err := lru.New[common.Hash, headerWithRaw](blocksLRUSize) + check.PanicIfErr(err) + + return &BlockHeaderByHashAccessor{ + cache: cache, + } +} + +type BlockByHashAccessor struct { + cache *lru.Cache[common.Hash, *types.RawBlockWithExtractedData] + + headersCache *BlockHeaderByHashAccessor +} + +func NewBlockByHashAccessor(blocksLRUSize int) *BlockByHashAccessor { + fc, err := lru.New[common.Hash, *types.RawBlockWithExtractedData](blocksLRUSize) + check.PanicIfErr(err) + + return &BlockByHashAccessor{ + cache: fc, + headersCache: NewBlockHeaderByHashAccessor(blocksLRUSize), + } +} + +type BlockHashByNumberAccessor struct { + // Currently, the block can be updated, so we cannot cache +} + +func NewBlockHashByNumberAccessor() *BlockHashByNumberAccessor { + return &BlockHashByNumberAccessor{} +} + +func (b *BlockHashByNumberAccessor) Get(tx db.RoTx, shardId types.ShardId, num types.BlockNumber) (common.Hash, error) { + return db.ReadBlockHashByNumber(tx, shardId, num) +} + +func (b *BlockHeaderByHashAccessor) Get(tx db.RoTx, shardId types.ShardId, hash common.Hash) (*types.Block, error) { + h, err := b.get(tx, shardId, hash) + if err != nil { + return nil, err + } + return h.block, nil +} + +func (b *BlockHeaderByHashAccessor) GetRaw(tx db.RoTx, shardId types.ShardId, hash common.Hash) ([]byte, error) { + h, err := b.get(tx, shardId, hash) + if err != nil { + return nil, err + } + return h.raw, nil +} + +func (b *BlockByHashAccessor) Get( + tx db.RoTx, shardId types.ShardId, hash common.Hash, +) (*types.RawBlockWithExtractedData, error) { + if rawBlockExt, ok := b.cache.Get(hash); ok { + return rawBlockExt, nil + } + + h, err := b.headersCache.get(tx, shardId, hash) + if err != nil { + return nil, err + } + + res := &types.RawBlockWithExtractedData{ + Block: h.raw, + } + + res.InTransactions, err = b.collectTxnIndexedEntities(tx, shardId, + db.TransactionTrieTable, h.block.InTransactionsRoot) + if err != nil { + return nil, err + } + res.InTxCounts, err = b.collectTxnCounts(tx, shardId, db.TransactionTrieTable, h.block.InTransactionsRoot) + if err != nil { + return nil, err + } + + res.OutTransactions, err = b.collectTxnIndexedEntities(tx, shardId, + db.TransactionTrieTable, h.block.OutTransactionsRoot) + if err != nil { + return nil, err + } + res.OutTxCounts, err = b.collectTxnCounts(tx, shardId, db.TransactionTrieTable, h.block.OutTransactionsRoot) + if err != nil { + return nil, err + } + + res.Receipts, err = b.collectTxnIndexedEntities(tx, shardId, db.ReceiptTrieTable, h.block.ReceiptsRoot) + if err != nil { + return nil, err + } + + res.ChildBlocks, err = b.collectChildBlocks(tx, shardId, h.block) + if err != nil { + return nil, err + } + + res.DbTimestamp, err = db.ReadBlockTimestamp(tx, shardId, hash) + if err != nil && !errors.Is(err, db.ErrKeyNotFound) { + return nil, err + } + + if shardId.IsMainShard() { + res.Config, err = b.collectConfig(tx, shardId, h.block) + if err != nil { + return nil, err + } + } + + return res, nil +} + +func (b *BlockHeaderByHashAccessor) get(tx db.RoTx, shardId types.ShardId, hash common.Hash) (headerWithRaw, error) { + if h, ok := b.cache.Get(hash); ok { + return h, nil + } + + raw, err := db.ReadBlockBytes(tx, shardId, hash) + if err != nil { + return headerWithRaw{}, err + } + + block := &types.Block{} + if err := block.UnmarshalNil(raw); err != nil { + return headerWithRaw{}, err + } + + if assert.Enable { + blockHash := block.Hash(shardId) + check.PanicIfNotf(blockHash == hash, "block hash mismatch: %s != %s", blockHash, hash) + } + + res := headerWithRaw{ + block: block, + raw: raw, + } + b.cache.Add(hash, res) + + return res, nil +} + +func (b *BlockByHashAccessor) collectTxnCounts( + tx db.RoTx, shardId types.ShardId, + tableName db.ShardedTableName, root common.Hash, +) ([][]byte, error) { + reader := mpt.NewDbReader(tx, shardId, tableName) + if err := reader.SetRootHash(root); err != nil { + return nil, err + } + + items := make([][]byte, 0, 16) + for k, v := range reader.Iterate() { + if len(k) != types.ShardIdSize { + continue + } + + var transactionIndex types.TransactionIndex + if err := transactionIndex.UnmarshalNil(v); err != nil { + return nil, fmt.Errorf("failed to unmarshal transaction index for shard %s: %w", k, err) + } + + txCount := &types.TxCount{ + ShardId: uint16(types.BytesToShardId(k)), + Count: transactionIndex, + } + + item, err := txCount.MarshalNil() + if err != nil { + return nil, err + } + items = append(items, item) + } + + return items, nil +} + +func (b *BlockByHashAccessor) collectTxnIndexedEntities( + tx db.RoTx, shardId types.ShardId, + tableName db.ShardedTableName, root common.Hash, +) ([][]byte, error) { + reader := mpt.NewDbReader(tx, shardId, tableName) + if err := reader.SetRootHash(root); err != nil { + return nil, err + } + + items := make([][]byte, 0, 1024) + for index := types.TransactionIndex(0); ; index++ { + entity, err := reader.Get(index.Bytes()) + if errors.Is(err, db.ErrKeyNotFound) { + break + } else if err != nil { + return nil, err + } + items = append(items, entity) + } + + return items, nil +} + +func (b *BlockByHashAccessor) collectChildBlocks( + tx db.RoTx, shardId types.ShardId, block *types.Block, +) ([]common.Hash, error) { + treeShards := NewDbShardBlocksTrieReader(tx, shardId, block.Id) + if err := treeShards.SetRootHash(block.ChildBlocksRootHash); err != nil { + return nil, err + } + + shards := make(map[types.ShardId]common.Hash) + for key, value := range treeShards.Iterate() { + shards[types.BytesToShardId(key)] = common.BytesToHash(value) + } + + values := make([]common.Hash, len(shards)) + for key, value := range shards { + values[key-1] = value // the main shard is omitted + } + return values, nil +} + +func (b *BlockByHashAccessor) collectConfig( + tx db.RoTx, shardId types.ShardId, block *types.Block, +) (map[string][]byte, error) { + res := mpt.NewDbReader(tx, shardId, db.ConfigTrieTable) + reader, err := res, res.SetRootHash(block.ConfigRoot) + if err != nil { + return nil, err + } + configMap := make(map[string][]byte) + for key, value := range reader.Iterate() { + configMap[string(key)] = value + } + return configMap, nil +} diff --git a/nil/internal/execution/block_cache.go b/nil/internal/execution/block_cache.go index caab8180d..e40736675 100644 --- a/nil/internal/execution/block_cache.go +++ b/nil/internal/execution/block_cache.go @@ -35,7 +35,7 @@ func getHashFn(es *ExecutionState, ref *types.Block) func(n uint64) (common.Hash lastKnownHash := cache[len(cache)-1] for { - data, err := es.shardAccessor.GetBlock().ByHash(lastKnownHash) + b, err := es.blockAccessor.GetByHash(es.tx, es.ShardId, lastKnownHash) if errors.Is(err, db.ErrKeyNotFound) { break } @@ -43,9 +43,9 @@ func getHashFn(es *ExecutionState, ref *types.Block) func(n uint64) (common.Hash return common.EmptyHash, err } - cache = append(cache, data.Block().PrevBlock) - lastKnownHash = data.Block().PrevBlock - lastKnownNumber := data.Block().Id.Uint64() - 1 + cache = append(cache, b.PrevBlock) + lastKnownHash = b.PrevBlock + lastKnownNumber := b.Id.Uint64() - 1 if n == lastKnownNumber { return lastKnownHash, nil } diff --git a/nil/internal/execution/block_generator.go b/nil/internal/execution/block_generator.go index c2eefdcf6..e9f2ec213 100644 --- a/nil/internal/execution/block_generator.go +++ b/nil/internal/execution/block_generator.go @@ -21,7 +21,7 @@ type BlockGeneratorParams struct { MainKeysPath string DisableConsensus bool ExecutionMode string - StateAccessor *StateAccessor + BlockAccessor *BlockAccessor FeeCalculator FeeCalculator EvmTracingHooks *tracing.Hooks } @@ -85,7 +85,7 @@ func NewBlockGenerator( executionState, err := NewExecutionState(rwTx, params.ShardId, StateParams{ Block: prevBlock, - StateAccessor: params.StateAccessor, + BlockAccessor: params.BlockAccessor, ConfigAccessor: configAccessor, FeeCalculator: params.FeeCalculator, Mode: params.ExecutionMode, diff --git a/nil/internal/execution/execution_state_test.go b/nil/internal/execution/execution_state_test.go index ba4fb21a9..e65943ed8 100644 --- a/nil/internal/execution/execution_state_test.go +++ b/nil/internal/execution/execution_state_test.go @@ -86,15 +86,13 @@ func (s *SuiteExecutionState) TestExecState() { }) s.Run("CheckTransactions", func() { - data, err := es.shardAccessor.GetBlock().ByHash(blockRes.BlockHash) + block, err := es.blockAccessor.GetByHash(es.tx, es.ShardId, blockRes.BlockHash) s.Require().NoError(err) - s.Require().NotNil(data) - s.Require().NotNil(data.Block()) transactionsRoot := NewDbTransactionTrieReader(tx, es.ShardId) - s.Require().NoError(transactionsRoot.SetRootHash(data.Block().InTransactionsRoot)) + s.Require().NoError(transactionsRoot.SetRootHash(block.InTransactionsRoot)) receiptsRoot := NewDbReceiptTrieReader(tx, es.ShardId) - s.Require().NoError(receiptsRoot.SetRootHash(data.Block().ReceiptsRoot)) + s.Require().NoError(receiptsRoot.SetRootHash(block.ReceiptsRoot)) var transactionIndex types.TransactionIndex for { diff --git a/nil/internal/execution/state.go b/nil/internal/execution/state.go index 5a3fac313..989516e53 100644 --- a/nil/internal/execution/state.go +++ b/nil/internal/execution/state.go @@ -130,7 +130,7 @@ type ExecutionState struct { // Tracing hooks set for every EVM created during execution EvmTracingHooks *tracing.Hooks - shardAccessor *shardAccessor + blockAccessor *BlockAccessor // Pointer to currently executed VM evm *vm.EVM @@ -261,17 +261,15 @@ type revision struct { // NewEVMBlockContext creates a new context for use in the EVM. func NewEVMBlockContext(es *ExecutionState) (*vm.BlockContext, error) { - data, err := es.shardAccessor.GetBlock().ByHash(es.PrevBlock) + header, err := es.blockAccessor.GetByHash(es.tx, es.ShardId, es.PrevBlock) if err != nil && !errors.Is(err, db.ErrKeyNotFound) { return nil, err } currentBlockId := uint64(0) - var header *types.Block time := uint64(0) rollbackCounter := uint32(0) if err == nil { - header = data.Block() currentBlockId = header.Id.Uint64() + 1 // TODO: we need to use header.Timestamp instead of but it's always zero for now. // Let's return some kind of logical timestamp (monotonic increasing block number). @@ -298,7 +296,7 @@ type StateParams struct { // Required parameters ConfigAccessor config.ConfigAccessor - StateAccessor *StateAccessor + BlockAccessor *BlockAccessor // Optional parameters FeeCalculator FeeCalculator @@ -363,7 +361,7 @@ func NewExecutionState(tx db.RoTx, shardId types.ShardId, params StateParams) (* journal: newJournal(), transientStorage: newTransientStorage(), - shardAccessor: params.StateAccessor.Access(tx, shardId), + blockAccessor: params.BlockAccessor, configAccessor: params.ConfigAccessor, BaseFee: baseFeePerGas, @@ -1605,14 +1603,12 @@ func (es *ExecutionState) buildTransactionTrees(outTxnValues []*types.Transactio func (es *ExecutionState) buildInboundTransactionTree() (common.Hash, error) { inTxnKeys := make([]types.TransactionIndex, 0, len(es.InTransactions)) - inTxnValues := make([]*types.Transaction, 0, len(es.InTransactions)) - for i, txn := range es.InTransactions { + for i := range es.InTransactions { inTxnKeys = append(inTxnKeys, types.TransactionIndex(i)) - inTxnValues = append(inTxnValues, txn) } inTransactionTree := NewDbTransactionTrie(es.tx, es.ShardId) - if err := inTransactionTree.UpdateBatch(inTxnKeys, inTxnValues); err != nil { + if err := inTransactionTree.UpdateBatch(inTxnKeys, es.InTransactions); err != nil { return common.Hash{}, err } @@ -2096,16 +2092,11 @@ func (es *ExecutionState) resetVm() { } func (es *ExecutionState) MarshalJSON() ([]byte, error) { - prevBlockRes, err := es.shardAccessor.GetBlock().ByHash(es.PrevBlock) + prevBlock, err := es.blockAccessor.GetByHash(es.tx, es.ShardId, es.PrevBlock) if err != nil && !errors.Is(err, db.ErrKeyNotFound) { return nil, err } - var prevBlock *types.Block - if err == nil { - prevBlock = prevBlockRes.Block() - } - data := struct { ContractTreeRoot common.Hash `json:"contractTreeRoot"` ReceiptTreeRoot common.Hash `json:"receiptTreeRoot"` diff --git a/nil/internal/execution/testaide.go b/nil/internal/execution/testaide.go index fcbb3d824..64aa31846 100644 --- a/nil/internal/execution/testaide.go +++ b/nil/internal/execution/testaide.go @@ -40,8 +40,8 @@ func NewTestExecutionState(t *testing.T, tx db.RoTx, shardId types.ShardId, para if params.ConfigAccessor == nil { params.ConfigAccessor = config.GetStubAccessor() } - if params.StateAccessor == nil { - params.StateAccessor = NewStateAccessor(32, 0) + if params.BlockAccessor == nil { + params.BlockAccessor = NewBlockAccessor(32) } es, err := NewExecutionState(tx, shardId, params) @@ -56,7 +56,7 @@ func NewTestExecutionState(t *testing.T, tx db.RoTx, shardId types.ShardId, para func NewTestBlockGeneratorParams(shardId types.ShardId, nShards uint32) BlockGeneratorParams { res := NewBlockGeneratorParams(shardId, nShards) - res.StateAccessor = NewStateAccessor(32, 0) + res.BlockAccessor = NewBlockAccessor(32) return res } diff --git a/nil/services/nilservice/config.go b/nil/services/nilservice/config.go index b79a10864..189fd4d2a 100644 --- a/nil/services/nilservice/config.go +++ b/nil/services/nilservice/config.go @@ -87,7 +87,7 @@ type Config struct { L1Fetcher rollup.L1BlockFetcher `yaml:"-"` - StateAccessor *execution.StateAccessor `yaml:"-"` + BlockAccessor *execution.BlockAccessor `yaml:"-"` NetworkManagerFactory func(ctx context.Context, cfg *Config, db db.DB) (network.Manager, error) `yaml:"-"` } @@ -227,6 +227,6 @@ func (c *Config) BlockGeneratorParams(shardId types.ShardId) execution.BlockGene EvmTracingHooks: verboseTracingHook, MainKeysPath: c.MainKeysPath, DisableConsensus: c.DisableConsensus, - StateAccessor: c.StateAccessor, + BlockAccessor: c.BlockAccessor, } } diff --git a/nil/services/nilservice/service.go b/nil/services/nilservice/service.go index 530728183..e859198b5 100644 --- a/nil/services/nilservice/service.go +++ b/nil/services/nilservice/service.go @@ -497,8 +497,8 @@ func CreateNode( return nil, err } - if cfg.StateAccessor == nil { - cfg.StateAccessor = execution.NewStateAccessor(1024, 0) + if cfg.BlockAccessor == nil { + cfg.BlockAccessor = execution.NewBlockAccessor(1024) } var txnPools map[types.ShardId]txnpool.Pool diff --git a/nil/services/rpc/rawapi/internal/local_call.go b/nil/services/rpc/rawapi/internal/local_call.go index 7eec120bd..c3327fe2b 100644 --- a/nil/services/rpc/rawapi/internal/local_call.go +++ b/nil/services/rpc/rawapi/internal/local_call.go @@ -228,7 +228,7 @@ func (api *localShardApiRo) Call( es, err := execution.NewExecutionState(tx, shardId, execution.StateParams{ Block: block, ConfigAccessor: configAccessor, - StateAccessor: api.accessor, + BlockAccessor: execution.NewBlockAccessor(32), // todo: use shared accessor Mode: execution.ModeReadOnly, }) if err != nil { @@ -286,7 +286,7 @@ func (api *localShardApiRo) Call( esOld, err := execution.NewExecutionState(tx, shardId, execution.StateParams{ Block: block, ConfigAccessor: config.GetStubAccessor(), - StateAccessor: api.accessor, + BlockAccessor: execution.NewBlockAccessor(32), // todo: use shared accessor Mode: execution.ModeReadOnly, }) if err != nil { diff --git a/nil/services/synccommittee/prover/tracer/traces_collector.go b/nil/services/synccommittee/prover/tracer/traces_collector.go index bf8cbe23b..d80ddaaea 100644 --- a/nil/services/synccommittee/prover/tracer/traces_collector.go +++ b/nil/services/synccommittee/prover/tracer/traces_collector.go @@ -39,7 +39,7 @@ type remoteTracesCollectorImpl struct { logger logging.Logger mptTracer *mpttracer.MPTTracer rwTx db.RwTx - stateAccessor *execution.StateAccessor + blockAccessor *execution.BlockAccessor lastTracedBlock *types.BlockNumber } @@ -65,7 +65,7 @@ func NewRemoteTracesCollector( client: client, logger: logger, rwTx: rwTx, - stateAccessor: execution.NewStateAccessor(32, 0), + blockAccessor: execution.NewBlockAccessor(32), }, nil } @@ -239,7 +239,7 @@ func (tc *remoteTracesCollectorImpl) executeBlockAndCollectTraces( execution.StateParams{ Block: prevBlock.Block, ConfigAccessor: configAccessor, - StateAccessor: tc.stateAccessor, + BlockAccessor: tc.blockAccessor, ContractMptRepository: tc.mptTracer, }, ) @@ -255,7 +255,7 @@ func (tc *remoteTracesCollectorImpl) executeBlockAndCollectTraces( // Create block generator params blockGeneratorParams := execution.NewBlockGeneratorParams(shardId, uint32(len(gasPrices))) blockGeneratorParams.EvmTracingHooks = es.EvmTracingHooks - blockGeneratorParams.StateAccessor = tc.stateAccessor + blockGeneratorParams.BlockAccessor = tc.blockAccessor // Create block generator blockGenerator, err := execution.NewBlockGeneratorWithEs(