Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NIT-2852] Add flags and other info for nitro --dev #2751

Merged
merged 8 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arbnode/inbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewTransactionStreamerForTest(t *testing.T, ownerAddress common.Address) (*
initReader := statetransfer.NewMemoryInitDataReader(&initData)

cacheConfig := core.DefaultCacheConfigWithScheme(env.GetTestStateScheme())
bc, err := gethexec.WriteOrTestBlockChain(chainDb, cacheConfig, initReader, chainConfig, arbostypes.TestInitMessage, gethexec.ConfigDefault.TxLookupLimit, 0)
bc, err := gethexec.WriteOrTestBlockChain(chainDb, cacheConfig, initReader, chainConfig, arbostypes.TestInitMessage, gethexec.ConfigDefault.TxLookupLimit, 0, common.Address{})

if err != nil {
Fail(t, err)
Expand Down
2 changes: 1 addition & 1 deletion arbos/arbosState/initialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func tryMarshalUnmarshal(input *statetransfer.ArbosInitializationInfo, t *testin
chainConfig := params.ArbitrumDevTestChainConfig()

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

triedbConfig := cacheConfig.TriedbConfig()
Expand Down
8 changes: 7 additions & 1 deletion arbos/arbosState/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func MakeGenesisBlock(parentHash common.Hash, blockNumber uint64, timestamp uint
return types.NewBlock(head, nil, nil, nil, trie.NewStackTrie(nil))
}

func InitializeArbosInDatabase(db ethdb.Database, cacheConfig *core.CacheConfig, initData statetransfer.InitDataReader, chainConfig *params.ChainConfig, initMessage *arbostypes.ParsedInitMessage, timestamp uint64, accountsPerSync uint) (root common.Hash, err error) {
func InitializeArbosInDatabase(db ethdb.Database, cacheConfig *core.CacheConfig, initData statetransfer.InitDataReader, chainConfig *params.ChainConfig, initMessage *arbostypes.ParsedInitMessage, timestamp uint64, accountsPerSync uint, chainOwner common.Address) (root common.Hash, err error) {
triedbConfig := cacheConfig.TriedbConfig()
triedbConfig.Preimages = false
stateDatabase := state.NewDatabaseWithConfig(db, triedbConfig)
Expand Down Expand Up @@ -96,6 +96,12 @@ func InitializeArbosInDatabase(db ethdb.Database, cacheConfig *core.CacheConfig,
log.Crit("failed to open the ArbOS state", "error", err)
}

if chainOwner != (common.Address{}) {
amsanghi marked this conversation as resolved.
Show resolved Hide resolved
err := arbosState.ChainOwners().Add(chainOwner)
if err != nil {
return common.Hash{}, err
}
}
addrTable := arbosState.AddressTable()
addrTableSize, err := addrTable.Size()
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions cmd/conf/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type InitConfig struct {
DownloadPoll time.Duration `koanf:"download-poll"`
DevInit bool `koanf:"dev-init"`
DevInitAddress string `koanf:"dev-init-address"`
DevMaxCodeSize uint64 `koanf:"dev-max-code-size"`
DevInitBlockNum uint64 `koanf:"dev-init-blocknum"`
Empty bool `koanf:"empty"`
ImportWasm bool `koanf:"import-wasm"`
Expand Down Expand Up @@ -47,6 +48,7 @@ var InitConfigDefault = InitConfig{
DownloadPoll: time.Minute,
DevInit: false,
DevInitAddress: "",
DevMaxCodeSize: 0,
DevInitBlockNum: 0,
Empty: false,
ImportWasm: false,
Expand Down Expand Up @@ -75,6 +77,7 @@ func InitConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.Bool(prefix+".dev-init", InitConfigDefault.DevInit, "init with dev data (1 account with balance) instead of file import")
f.String(prefix+".dev-init-address", InitConfigDefault.DevInitAddress, "Address of dev-account. Leave empty to use the dev-wallet.")
f.Uint64(prefix+".dev-init-blocknum", InitConfigDefault.DevInitBlockNum, "Number of preinit blocks. Must exist in ancient database.")
f.Uint64(prefix+".dev-max-code-size", InitConfigDefault.DevMaxCodeSize, "Max code size for dev accounts")
f.Bool(prefix+".empty", InitConfigDefault.Empty, "init with empty state")
f.Bool(prefix+".import-wasm", InitConfigDefault.ImportWasm, "if set, import the wasm directory when downloading a database (contains executable code - only use with highly trusted source)")
f.Bool(prefix+".then-quit", InitConfigDefault.ThenQuit, "quit after init is done")
Expand Down
9 changes: 8 additions & 1 deletion cmd/nitro/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,9 @@ func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeCo
if err != nil {
return chainDb, nil, err
}
if config.Init.DevInit && config.Init.DevMaxCodeSize != 0 {
chainConfig.ArbitrumChainParams.MaxCodeSize = config.Init.DevMaxCodeSize
}
testUpdateTxIndex(chainDb, chainConfig, &txIndexWg)
ancients, err := chainDb.Ancients()
if err != nil {
Expand Down Expand Up @@ -788,7 +791,11 @@ func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeCo
if !emptyBlockChain && (cacheConfig.StateScheme == rawdb.PathScheme) && config.Init.Force {
return chainDb, nil, errors.New("It is not possible to force init with non-empty blockchain when using path scheme")
}
l2BlockChain, err = gethexec.WriteOrTestBlockChain(chainDb, cacheConfig, initDataReader, chainConfig, parsedInitMessage, config.Execution.TxLookupLimit, config.Init.AccountsPerSync)
var chainOwner common.Address
if config.Init.DevInit {
chainOwner = common.HexToAddress(config.Init.DevInitAddress)
}
l2BlockChain, err = gethexec.WriteOrTestBlockChain(chainDb, cacheConfig, initDataReader, chainConfig, parsedInitMessage, config.Execution.TxLookupLimit, config.Init.AccountsPerSync, chainOwner)
if err != nil {
return chainDb, nil, err
}
Expand Down
1 change: 1 addition & 0 deletions cmd/util/confighelpers/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func devFlagArgs() []string {
"--init.empty=false",
"--http.port", "8547",
"--http.addr", "127.0.0.1",
"--http.api=net,web3,eth,arb,arbdebug,debug",
}
return args
}
Expand Down
8 changes: 4 additions & 4 deletions execution/gethexec/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (c *CachingConfig) Validate() error {
return c.validateStateScheme()
}

func WriteOrTestGenblock(chainDb ethdb.Database, cacheConfig *core.CacheConfig, initData statetransfer.InitDataReader, chainConfig *params.ChainConfig, initMessage *arbostypes.ParsedInitMessage, accountsPerSync uint) error {
func WriteOrTestGenblock(chainDb ethdb.Database, cacheConfig *core.CacheConfig, initData statetransfer.InitDataReader, chainConfig *params.ChainConfig, initMessage *arbostypes.ParsedInitMessage, accountsPerSync uint, chainOwner common.Address) error {
EmptyHash := common.Hash{}
prevHash := EmptyHash
prevDifficulty := big.NewInt(0)
Expand All @@ -146,7 +146,7 @@ func WriteOrTestGenblock(chainDb ethdb.Database, cacheConfig *core.CacheConfig,
}
timestamp = prevHeader.Time
}
stateRoot, err := arbosState.InitializeArbosInDatabase(chainDb, cacheConfig, initData, chainConfig, initMessage, timestamp, accountsPerSync)
stateRoot, err := arbosState.InitializeArbosInDatabase(chainDb, cacheConfig, initData, chainConfig, initMessage, timestamp, accountsPerSync, chainOwner)
if err != nil {
return err
}
Expand Down Expand Up @@ -213,7 +213,7 @@ func GetBlockChain(chainDb ethdb.Database, cacheConfig *core.CacheConfig, chainC
return core.NewBlockChain(chainDb, cacheConfig, chainConfig, nil, nil, engine, vmConfig, shouldPreserveFalse, &txLookupLimit)
}

func WriteOrTestBlockChain(chainDb ethdb.Database, cacheConfig *core.CacheConfig, initData statetransfer.InitDataReader, chainConfig *params.ChainConfig, initMessage *arbostypes.ParsedInitMessage, txLookupLimit uint64, accountsPerSync uint) (*core.BlockChain, error) {
func WriteOrTestBlockChain(chainDb ethdb.Database, cacheConfig *core.CacheConfig, initData statetransfer.InitDataReader, chainConfig *params.ChainConfig, initMessage *arbostypes.ParsedInitMessage, txLookupLimit uint64, accountsPerSync uint, chainOwner common.Address) (*core.BlockChain, error) {
emptyBlockChain := rawdb.ReadHeadHeader(chainDb) == nil
if !emptyBlockChain && (cacheConfig.StateScheme == rawdb.PathScheme) {
// When using path scheme, and the stored state trie is not empty,
Expand All @@ -222,7 +222,7 @@ func WriteOrTestBlockChain(chainDb ethdb.Database, cacheConfig *core.CacheConfig
return GetBlockChain(chainDb, cacheConfig, chainConfig, txLookupLimit)
}

err := WriteOrTestGenblock(chainDb, cacheConfig, initData, chainConfig, initMessage, accountsPerSync)
err := WriteOrTestGenblock(chainDb, cacheConfig, initData, chainConfig, initMessage, accountsPerSync, chainOwner)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions system_tests/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ func createNonL1BlockChainWithStackConfig(
}
}
coreCacheConfig := gethexec.DefaultCacheConfigFor(stack, &execConfig.Caching)
blockchain, err := gethexec.WriteOrTestBlockChain(chainDb, coreCacheConfig, initReader, chainConfig, initMessage, ExecConfigDefaultTest(t).TxLookupLimit, 0)
blockchain, err := gethexec.WriteOrTestBlockChain(chainDb, coreCacheConfig, initReader, chainConfig, initMessage, ExecConfigDefaultTest(t).TxLookupLimit, 0, common.Address{})
Require(t, err)

return info, stack, chainDb, arbDb, blockchain
Expand Down Expand Up @@ -1437,7 +1437,7 @@ func Create2ndNodeWithConfig(
chainConfig := firstExec.ArbInterface.BlockChain().Config()

coreCacheConfig := gethexec.DefaultCacheConfigFor(chainStack, &execConfig.Caching)
blockchain, err := gethexec.WriteOrTestBlockChain(chainDb, coreCacheConfig, initReader, chainConfig, initMessage, ExecConfigDefaultTest(t).TxLookupLimit, 0)
blockchain, err := gethexec.WriteOrTestBlockChain(chainDb, coreCacheConfig, initReader, chainConfig, initMessage, ExecConfigDefaultTest(t).TxLookupLimit, 0, common.Address{})
Require(t, err)

AddValNodeIfNeeded(t, ctx, nodeConfig, true, "", valnodeConfig.Wasm.RootPath)
Expand Down
1 change: 1 addition & 0 deletions system_tests/state_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func FuzzStateTransition(f *testing.F) {
initMessage,
0,
0,
common.Address{},
)
if err != nil {
panic(err)
Expand Down
Loading