Skip to content

Commit

Permalink
Merge pull request OffchainLabs#2612 from OffchainLabs/fix-wasm-rebui…
Browse files Browse the repository at this point in the history
…ld-stylus-target

populate stylus target cache before rebuilding wasm store
  • Loading branch information
PlasmaPower committed Aug 26, 2024
1 parent 4650d89 commit b26e84e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/nitro/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeCo
startBlockHash = latestBlock.Hash()
}
log.Info("Starting or continuing rebuilding of wasm store", "codeHash", position, "startBlockHash", startBlockHash)
if err := gethexec.RebuildWasmStore(ctx, wasmDb, chainDb, config.Execution.RPC.MaxRecreateStateDepth, l2BlockChain, position, startBlockHash); err != nil {
if err := gethexec.RebuildWasmStore(ctx, wasmDb, chainDb, config.Execution.RPC.MaxRecreateStateDepth, &config.Execution.StylusTarget, l2BlockChain, position, startBlockHash); err != nil {
return nil, nil, fmt.Errorf("error rebuilding of wasm store: %w", err)
}
}
Expand Down
15 changes: 11 additions & 4 deletions execution/gethexec/executionengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ func (s *ExecutionEngine) MarkFeedStart(to arbutil.MessageIndex) {
}
}

func (s *ExecutionEngine) Initialize(rustCacheSize uint32, targetConfig *StylusTargetConfig) error {
if rustCacheSize != 0 {
programs.ResizeWasmLruCache(rustCacheSize)
}
func populateStylusTargetCache(targetConfig *StylusTargetConfig) error {
var effectiveStylusTarget string
target := rawdb.LocalTarget()
switch target {
Expand All @@ -171,6 +168,16 @@ func (s *ExecutionEngine) Initialize(rustCacheSize uint32, targetConfig *StylusT
return nil
}

func (s *ExecutionEngine) Initialize(rustCacheSize uint32, targetConfig *StylusTargetConfig) error {
if rustCacheSize != 0 {
programs.ResizeWasmLruCache(rustCacheSize)
}
if err := populateStylusTargetCache(targetConfig); err != nil {
return fmt.Errorf("error populating stylus target cache: %w", err)
}
return nil
}

func (s *ExecutionEngine) SetRecorder(recorder *BlockRecorder) {
if s.Started() {
panic("trying to set recorder after start")
Expand Down
7 changes: 6 additions & 1 deletion execution/gethexec/wasmstorerebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,14 @@ func WriteToKeyValueStore[T any](store ethdb.KeyValueStore, key []byte, val T) e
// It also stores a special value that is only set once when rebuilding commenced in RebuildingStartBlockHashKey as the block
// time of the latest block when rebuilding was first called, this is used to avoid recomputing of assembly and module of
// contracts that were created after rebuilding commenced since they would anyway already be added during sync.
func RebuildWasmStore(ctx context.Context, wasmStore ethdb.KeyValueStore, chainDb ethdb.Database, maxRecreateStateDepth int64, l2Blockchain *core.BlockChain, position, rebuildingStartBlockHash common.Hash) error {
func RebuildWasmStore(ctx context.Context, wasmStore ethdb.KeyValueStore, chainDb ethdb.Database, maxRecreateStateDepth int64, targetConfig *StylusTargetConfig, l2Blockchain *core.BlockChain, position, rebuildingStartBlockHash common.Hash) error {
var err error
var stateDb *state.StateDB

if err := populateStylusTargetCache(targetConfig); err != nil {
return fmt.Errorf("error populating stylus target cache: %w", err)
}

latestHeader := l2Blockchain.CurrentBlock()
// Attempt to get state at the start block when rebuilding commenced, if not available (in case of non-archival nodes) use latest state
rebuildingStartHeader := l2Blockchain.GetHeaderByHash(rebuildingStartBlockHash)
Expand Down
3 changes: 2 additions & 1 deletion system_tests/program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1891,7 +1891,8 @@ func TestWasmStoreRebuilding(t *testing.T) {

// Start rebuilding and wait for it to finish
log.Info("starting rebuilding of wasm store")
Require(t, gethexec.RebuildWasmStore(ctx, wasmDbAfterDelete, nodeB.ExecNode.ChainDB, nodeB.ExecNode.ConfigFetcher().RPC.MaxRecreateStateDepth, bc, common.Hash{}, bc.CurrentBlock().Hash()))
execConfig := nodeB.ExecNode.ConfigFetcher()
Require(t, gethexec.RebuildWasmStore(ctx, wasmDbAfterDelete, nodeB.ExecNode.ChainDB, execConfig.RPC.MaxRecreateStateDepth, &execConfig.StylusTarget, bc, common.Hash{}, bc.CurrentBlock().Hash()))

wasmDbAfterRebuild := nodeB.ExecNode.Backend.ArbInterface().BlockChain().StateCache().WasmStore()

Expand Down

0 comments on commit b26e84e

Please sign in to comment.