Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshvanahalli committed Jan 28, 2025
2 parents 860d5d4 + fa80b55 commit 4c8f61a
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 3 deletions.
4 changes: 2 additions & 2 deletions arbnode/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (mr *MaintenanceRunner) maybeRunMaintenance(ctx context.Context) time.Durat
}

func (mr *MaintenanceRunner) runMaintenance() {
log.Info("Compacting databases (this may take a while...)")
log.Info("Compacting databases and flushing triedb to disk (this may take a while...)")
results := make(chan error, len(mr.dbs))
expected := 0
for _, db := range mr.dbs {
Expand All @@ -191,5 +191,5 @@ func (mr *MaintenanceRunner) runMaintenance() {
log.Warn("maintenance error", "err", err)
}
}
log.Info("Done compacting databases")
log.Info("Done compacting databases and flushing triedb to disk")
}
3 changes: 3 additions & 0 deletions execution/gethexec/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type CachingConfig struct {
TrieTimeLimit time.Duration `koanf:"trie-time-limit"`
TrieDirtyCache int `koanf:"trie-dirty-cache"`
TrieCleanCache int `koanf:"trie-clean-cache"`
TrieCapLimit uint32 `koanf:"trie-cap-limit"`
SnapshotCache int `koanf:"snapshot-cache"`
DatabaseCache int `koanf:"database-cache"`
SnapshotRestoreGasLimit uint64 `koanf:"snapshot-restore-gas-limit"`
Expand All @@ -53,6 +54,7 @@ func CachingConfigAddOptions(prefix string, f *flag.FlagSet) {
f.Int(prefix+".trie-clean-cache", DefaultCachingConfig.TrieCleanCache, "amount of memory in megabytes to cache unchanged state trie nodes with")
f.Int(prefix+".snapshot-cache", DefaultCachingConfig.SnapshotCache, "amount of memory in megabytes to cache state snapshots with")
f.Int(prefix+".database-cache", DefaultCachingConfig.DatabaseCache, "amount of memory in megabytes to cache database contents with")
f.Uint32(prefix+".trie-cap-limit", DefaultCachingConfig.TrieCapLimit, "amount of memory in megabytes to be used in the TrieDB Cap operation during maintenance")
f.Uint64(prefix+".snapshot-restore-gas-limit", DefaultCachingConfig.SnapshotRestoreGasLimit, "maximum gas rolled back to recover snapshot")
f.Uint32(prefix+".max-number-of-blocks-to-skip-state-saving", DefaultCachingConfig.MaxNumberOfBlocksToSkipStateSaving, "maximum number of blocks to skip state saving to persistent storage (archive node only) -- warning: this option seems to cause issues")
f.Uint64(prefix+".max-amount-of-gas-to-skip-state-saving", DefaultCachingConfig.MaxAmountOfGasToSkipStateSaving, "maximum amount of gas in blocks to skip saving state to Persistent storage (archive node only) -- warning: this option seems to cause issues")
Expand All @@ -74,6 +76,7 @@ var DefaultCachingConfig = CachingConfig{
TrieTimeLimit: time.Hour,
TrieDirtyCache: 1024,
TrieCleanCache: 600,
TrieCapLimit: 100,
SnapshotCache: 400,
DatabaseCache: 2048,
SnapshotRestoreGasLimit: 300_000_000_000,
Expand Down
6 changes: 6 additions & 0 deletions execution/gethexec/executionengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1054,3 +1054,9 @@ func (s *ExecutionEngine) Start(ctx_in context.Context) {
})
}
}

func (s *ExecutionEngine) Maintenance(capLimit uint64) error {
s.createBlocksMutex.Lock()
defer s.createBlocksMutex.Unlock()
return s.bc.FlushTrieDB(common.StorageSize(capLimit))
}
6 changes: 6 additions & 0 deletions execution/gethexec/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/execution"
"github.com/offchainlabs/nitro/solgen/go/precompilesgen"
"github.com/offchainlabs/nitro/util/arbmath"
"github.com/offchainlabs/nitro/util/dbutil"
"github.com/offchainlabs/nitro/util/headerreader"
)
Expand Down Expand Up @@ -483,6 +484,11 @@ func (n *ExecutionNode) BlockNumberToMessageIndex(blockNum uint64) (arbutil.Mess
}

func (n *ExecutionNode) Maintenance() error {
trieCapLimitBytes := arbmath.SaturatingUMul(uint64(n.ConfigFetcher().Caching.TrieCapLimit), 1024*1024)
err := n.ExecEngine.Maintenance(trieCapLimitBytes)
if err != nil {
return err
}
return n.ChainDB.Compact(nil, nil)
}

Expand Down
2 changes: 1 addition & 1 deletion go-ethereum
46 changes: 46 additions & 0 deletions system_tests/maintenance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2021-2025, Offchain Labs, Inc.
// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE

package arbtest

import (
"context"
"fmt"
"math/big"
"testing"
)

func TestMaintenance(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

builder := NewNodeBuilder(ctx).DefaultConfig(t, false)
cleanup := builder.Build(t)
defer cleanup()

numberOfTransfers := 10
for i := 2; i < 3+numberOfTransfers; i++ {
account := fmt.Sprintf("User%d", i)
builder.L2Info.GenerateAccount(account)

tx := builder.L2Info.PrepareTx("Owner", account, builder.L2Info.TransferGas, big.NewInt(1e12), nil)
err := builder.L2.Client.SendTransaction(ctx, tx)
Require(t, err)
_, err = builder.L2.EnsureTxSucceeded(tx)
Require(t, err)
}

err := builder.L2.ExecNode.Maintenance()
Require(t, err)

for i := 2; i < 3+numberOfTransfers; i++ {
account := fmt.Sprintf("User%d", i)
balance, err := builder.L2.Client.BalanceAt(ctx, builder.L2Info.GetAddress(account), nil)
Require(t, err)
if balance.Cmp(big.NewInt(int64(1e12))) != 0 {
t.Fatal("Unexpected balance:", balance, "for account:", account)
}
}
}

0 comments on commit 4c8f61a

Please sign in to comment.