From 8bfc9e680ad20ef8e5d4d292167af3c73a6149e1 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Fri, 23 Aug 2024 17:21:21 +0530 Subject: [PATCH 1/2] Allow force rebuilding of local wasm store --- cmd/conf/init.go | 14 +++++++++++--- cmd/nitro/init.go | 16 ++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/cmd/conf/init.go b/cmd/conf/init.go index d88bcdd241..f360691693 100644 --- a/cmd/conf/init.go +++ b/cmd/conf/init.go @@ -30,7 +30,7 @@ type InitConfig struct { PruneThreads int `koanf:"prune-threads"` PruneTrieCleanCache int `koanf:"prune-trie-clean-cache"` RecreateMissingStateFrom uint64 `koanf:"recreate-missing-state-from"` - RebuildLocalWasm bool `koanf:"rebuild-local-wasm"` + RebuildLocalWasm string `koanf:"rebuild-local-wasm"` ReorgToBatch int64 `koanf:"reorg-to-batch"` ReorgToMessageBatch int64 `koanf:"reorg-to-message-batch"` ReorgToBlockBatch int64 `koanf:"reorg-to-block-batch"` @@ -56,7 +56,7 @@ var InitConfigDefault = InitConfig{ PruneThreads: runtime.NumCPU(), PruneTrieCleanCache: 600, RecreateMissingStateFrom: 0, // 0 = disabled - RebuildLocalWasm: true, + RebuildLocalWasm: "auto", ReorgToBatch: -1, ReorgToMessageBatch: -1, ReorgToBlockBatch: -1, @@ -82,10 +82,14 @@ func InitConfigAddOptions(prefix string, f *pflag.FlagSet) { f.Int(prefix+".prune-threads", InitConfigDefault.PruneThreads, "the number of threads to use when pruning") f.Int(prefix+".prune-trie-clean-cache", InitConfigDefault.PruneTrieCleanCache, "amount of memory in megabytes to cache unchanged state trie nodes with when traversing state database during pruning") f.Uint64(prefix+".recreate-missing-state-from", InitConfigDefault.RecreateMissingStateFrom, "block number to start recreating missing states from (0 = disabled)") - f.Bool(prefix+".rebuild-local-wasm", InitConfigDefault.RebuildLocalWasm, "rebuild local wasm database on boot if needed (otherwise-will be done lazily)") f.Int64(prefix+".reorg-to-batch", InitConfigDefault.ReorgToBatch, "rolls back the blockchain to a specified batch number") f.Int64(prefix+".reorg-to-message-batch", InitConfigDefault.ReorgToMessageBatch, "rolls back the blockchain to the first batch at or before a given message index") f.Int64(prefix+".reorg-to-block-batch", InitConfigDefault.ReorgToBlockBatch, "rolls back the blockchain to the first batch at or before a given block number") + f.String(prefix+".rebuild-local-wasm", InitConfigDefault.RebuildLocalWasm, "rebuild local wasm database on boot if needed (otherwise-will be done lazily). Three modes are supported \n"+ + "\"auto\"- (enabled by default) if any previous rebuilding attempt was successful then rebuilding is disabled else continues to rebuild,\n"+ + "\"force\"- force rebuilding which would commence rebuilding despite the status of previous attempts,\n"+ + "\"false\"- do not rebuild on startup", + ) } func (c *InitConfig) Validate() error { @@ -110,6 +114,10 @@ func (c *InitConfig) Validate() error { } } } + c.RebuildLocalWasm = strings.ToLower(c.RebuildLocalWasm) + if c.RebuildLocalWasm != "auto" && c.RebuildLocalWasm != "force" && c.RebuildLocalWasm != "false" { + return fmt.Errorf("invalid value of rebuild-local-wasm, want: auto or force or false, got: %s", c.RebuildLocalWasm) + } return nil } diff --git a/cmd/nitro/init.go b/cmd/nitro/init.go index d9ae0df3b0..fc3439a56d 100644 --- a/cmd/nitro/init.go +++ b/cmd/nitro/init.go @@ -532,13 +532,21 @@ func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeCo if err = gethexec.WriteToKeyValueStore(wasmDb, gethexec.RebuildingPositionKey, gethexec.RebuildingDone); err != nil { return nil, nil, fmt.Errorf("unable to set rebuilding status of wasm store to done: %w", err) } - } else if config.Init.RebuildLocalWasm { - position, err := gethexec.ReadFromKeyValueStore[common.Hash](wasmDb, gethexec.RebuildingPositionKey) - if err != nil { - log.Info("Unable to get codehash position in rebuilding of wasm store, its possible it isnt initialized yet, so initializing it and starting rebuilding", "err", err) + } else if config.Init.RebuildLocalWasm != "false" { + var position common.Hash + if config.Init.RebuildLocalWasm == "force" { + log.Info("Commencing force rebuilding of wasm store by setting codehash position in rebuilding to beginning") if err := gethexec.WriteToKeyValueStore(wasmDb, gethexec.RebuildingPositionKey, common.Hash{}); err != nil { return nil, nil, fmt.Errorf("unable to initialize codehash position in rebuilding of wasm store to beginning: %w", err) } + } else { + position, err = gethexec.ReadFromKeyValueStore[common.Hash](wasmDb, gethexec.RebuildingPositionKey) + if err != nil { + log.Info("Unable to get codehash position in rebuilding of wasm store, its possible it isnt initialized yet, so initializing it and starting rebuilding", "err", err) + if err := gethexec.WriteToKeyValueStore(wasmDb, gethexec.RebuildingPositionKey, common.Hash{}); err != nil { + return nil, nil, fmt.Errorf("unable to initialize codehash position in rebuilding of wasm store to beginning: %w", err) + } + } } if position != gethexec.RebuildingDone { startBlockHash, err := gethexec.ReadFromKeyValueStore[common.Hash](wasmDb, gethexec.RebuildingStartBlockHashKey) From 803384395ad64c116ec543f459888e059fa9e95a Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Fri, 23 Aug 2024 19:36:24 +0530 Subject: [PATCH 2/2] fix G115 lint errors --- system_tests/contract_tx_test.go | 1 + util/blobs/blobs.go | 2 ++ 2 files changed, 3 insertions(+) diff --git a/system_tests/contract_tx_test.go b/system_tests/contract_tx_test.go index 7d66e516b4..c1ef840c43 100644 --- a/system_tests/contract_tx_test.go +++ b/system_tests/contract_tx_test.go @@ -51,6 +51,7 @@ func TestContractTxDeploy(t *testing.T) { 0xF3, // RETURN } var requestId common.Hash + // #nosec G115 requestId[0] = uint8(stateNonce) contractTx := &types.ArbitrumContractTx{ ChainId: params.ArbitrumDevTestChainConfig().ChainID, diff --git a/util/blobs/blobs.go b/util/blobs/blobs.go index 405c776bad..f5914edd2e 100644 --- a/util/blobs/blobs.go +++ b/util/blobs/blobs.go @@ -41,6 +41,7 @@ func fillBlobBits(blob []byte, data []byte) ([]byte, error) { accBits += 8 data = data[1:] } + // #nosec G115 blob[fieldElement*32] = uint8(acc & ((1 << spareBlobBits) - 1)) accBits -= spareBlobBits if accBits < 0 { @@ -88,6 +89,7 @@ func DecodeBlobs(blobs []kzg4844.Blob) ([]byte, error) { acc |= uint16(blob[fieldIndex*32]) << accBits accBits += spareBlobBits if accBits >= 8 { + // #nosec G115 rlpData = append(rlpData, uint8(acc)) acc >>= 8 accBits -= 8