Skip to content

Commit

Permalink
Uses env var to define trie in NewMemoryBackedStateDB and NewArbosMem…
Browse files Browse the repository at this point in the history
…oryBackedArbOSState
  • Loading branch information
diegoximenes committed Jun 17, 2024
1 parent 350de23 commit 6610db5
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
3 changes: 2 additions & 1 deletion arbnode/inbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/offchainlabs/nitro/statetransfer"

"github.com/offchainlabs/nitro/util/arbmath"
"github.com/offchainlabs/nitro/util/env"
"github.com/offchainlabs/nitro/util/testhelpers"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -54,7 +55,7 @@ func NewTransactionStreamerForTest(t *testing.T, ownerAddress common.Address) (*
arbDb := rawdb.NewMemoryDatabase()
initReader := statetransfer.NewMemoryInitDataReader(&initData)

cacheConfig := core.DefaultCacheConfigWithScheme(testhelpers.GetTestStateScheme())
cacheConfig := core.DefaultCacheConfigWithScheme(env.GetTestStateScheme())
bc, err := gethexec.WriteOrTestBlockChain(chainDb, cacheConfig, initReader, chainConfig, arbostypes.TestInitMessage, gethexec.ConfigDefaultTest().TxLookupLimit, 0)

if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion arbos/arbosState/arbosstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/trie/triedb/hashdb"
"github.com/ethereum/go-ethereum/trie/triedb/pathdb"

"github.com/offchainlabs/nitro/arbcompress"
Expand All @@ -31,6 +32,7 @@ import (
"github.com/offchainlabs/nitro/arbos/retryables"
"github.com/offchainlabs/nitro/arbos/storage"
"github.com/offchainlabs/nitro/arbos/util"
"github.com/offchainlabs/nitro/util/env"
)

// ArbosState contains ArbOS-related state. It is backed by ArbOS's storage in the persistent stateDB.
Expand Down Expand Up @@ -117,7 +119,11 @@ func OpenSystemArbosStateOrPanic(stateDB vm.StateDB, tracingInfo *util.TracingIn
// NewArbosMemoryBackedArbOSState creates and initializes a memory-backed ArbOS state (for testing only)
func NewArbosMemoryBackedArbOSState() (*ArbosState, *state.StateDB) {
raw := rawdb.NewMemoryDatabase()
db := state.NewDatabaseWithConfig(raw, &trie.Config{Preimages: false, PathDB: pathdb.Defaults})
trieConfig := &trie.Config{Preimages: false, PathDB: pathdb.Defaults}
if env.GetTestStateScheme() == rawdb.HashScheme {
trieConfig = &trie.Config{Preimages: false, HashDB: hashdb.Defaults}
}
db := state.NewDatabaseWithConfig(raw, trieConfig)
statedb, err := state.New(common.Hash{}, db, nil)
if err != nil {
log.Crit("failed to init empty statedb", "error", err)
Expand Down
3 changes: 2 additions & 1 deletion arbos/arbosState/initialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/offchainlabs/nitro/arbos/arbostypes"
"github.com/offchainlabs/nitro/arbos/burn"
"github.com/offchainlabs/nitro/statetransfer"
"github.com/offchainlabs/nitro/util/env"
"github.com/offchainlabs/nitro/util/testhelpers"
)

Expand Down Expand Up @@ -62,7 +63,7 @@ func tryMarshalUnmarshal(input *statetransfer.ArbosInitializationInfo, t *testin
initReader := statetransfer.NewMemoryInitDataReader(&initData)
chainConfig := params.ArbitrumDevTestChainConfig()

cacheConfig := core.DefaultCacheConfigWithScheme(testhelpers.GetTestStateScheme())
cacheConfig := core.DefaultCacheConfigWithScheme(env.GetTestStateScheme())
stateroot, err := InitializeArbosInDatabase(raw, cacheConfig, initReader, chainConfig, arbostypes.TestInitMessage, 0, 0)
Require(t, err)

Expand Down
8 changes: 7 additions & 1 deletion arbos/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/trie/triedb/hashdb"
"github.com/ethereum/go-ethereum/trie/triedb/pathdb"
"github.com/offchainlabs/nitro/arbos/burn"
"github.com/offchainlabs/nitro/arbos/util"
"github.com/offchainlabs/nitro/util/arbmath"
"github.com/offchainlabs/nitro/util/env"
)

// Storage allows ArbOS to store data persistently in the Ethereum-compatible stateDB. This is represented in
Expand Down Expand Up @@ -85,7 +87,11 @@ func NewMemoryBacked(burner burn.Burner) *Storage {
// Only used for testing.
func NewMemoryBackedStateDB() vm.StateDB {
raw := rawdb.NewMemoryDatabase()
db := state.NewDatabaseWithConfig(raw, &trie.Config{Preimages: false, PathDB: pathdb.Defaults})
trieConfig := &trie.Config{Preimages: false, PathDB: pathdb.Defaults}
if env.GetTestStateScheme() == rawdb.HashScheme {
trieConfig = &trie.Config{Preimages: false, HashDB: hashdb.Defaults}
}
db := state.NewDatabaseWithConfig(raw, trieConfig)
statedb, err := state.New(common.Hash{}, db, nil)
if err != nil {
panic("failed to init empty statedb")
Expand Down
4 changes: 2 additions & 2 deletions execution/gethexec/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/offchainlabs/nitro/arbos/arbostypes"
"github.com/offchainlabs/nitro/gethhook"
"github.com/offchainlabs/nitro/statetransfer"
"github.com/offchainlabs/nitro/util/testhelpers"
"github.com/offchainlabs/nitro/util/env"
)

type CachingConfig struct {
Expand Down Expand Up @@ -94,7 +94,7 @@ var TestCachingConfig = CachingConfig{
MaxNumberOfBlocksToSkipStateSaving: 0,
MaxAmountOfGasToSkipStateSaving: 0,
StylusLRUCache: 0,
StateScheme: testhelpers.GetTestStateScheme(),
StateScheme: env.GetTestStateScheme(),
}

var (
Expand Down
4 changes: 2 additions & 2 deletions system_tests/state_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/offchainlabs/nitro/arbstate"
"github.com/offchainlabs/nitro/arbstate/daprovider"
"github.com/offchainlabs/nitro/statetransfer"
"github.com/offchainlabs/nitro/util/testhelpers"
"github.com/offchainlabs/nitro/util/env"
)

func BuildBlock(
Expand Down Expand Up @@ -138,7 +138,7 @@ func FuzzStateTransition(f *testing.F) {
ChainConfig: chainConfig,
SerializedChainConfig: serializedChainConfig,
}
cacheConfig := core.DefaultCacheConfigWithScheme(testhelpers.GetTestStateScheme())
cacheConfig := core.DefaultCacheConfigWithScheme(env.GetTestStateScheme())
stateRoot, err := arbosState.InitializeArbosInDatabase(
chainDb,
cacheConfig,
Expand Down
2 changes: 1 addition & 1 deletion util/testhelpers/statescheme.go → util/env/env.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2021-2024, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE

package testhelpers
package env

import (
"os"
Expand Down

0 comments on commit 6610db5

Please sign in to comment.