Skip to content

Commit

Permalink
feat: support get checkpoint withdraw proof in pbss
Browse files Browse the repository at this point in the history
  • Loading branch information
will@2012 committed Mar 28, 2024
1 parent 4e077c7 commit 7c7f9aa
Show file tree
Hide file tree
Showing 20 changed files with 700 additions and 29 deletions.
4 changes: 3 additions & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ var (
utils.TxLookupLimitFlag,
utils.TransactionHistoryFlag,
utils.StateHistoryFlag,
utils.ProposeBlockIntervalFlag,
utils.PathDBSyncFlag,
utils.ProposeBlockIntervalFlag,
utils.EnableCheckpointFlag,
utils.MaxCheckpointNumberFlag,
utils.LightServeFlag,
utils.LightIngressFlag,
utils.LightEgressFlag,
Expand Down
22 changes: 20 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,28 @@ var (
}
PathDBSyncFlag = &cli.BoolFlag{
Name: "pathdb.sync",
Usage: "sync flush nodes cache to disk in path scheme",
Usage: "Sync flush nodes cache to disk in path scheme",
Value: false,
Category: flags.StateCategory,
}
ProposeBlockIntervalFlag = &cli.Uint64Flag{
Name: "pathdb.proposeblock",
Usage: "keep the same with op-proposer propose block interval",
Usage: "Keep the same with op-proposer propose block interval",
Value: pathdb.DefaultProposeBlockInterval,
Category: flags.StateCategory,
}
EnableCheckpointFlag = &cli.BoolFlag{
Name: "pathdb.enablecheckpoint",
Usage: "Enable trie db checkpoint for get withdraw-contract proof",
Value: true,
Category: flags.StateCategory,
}
MaxCheckpointNumberFlag = &cli.Uint64Flag{
Name: "pathdb.maxcheckpointnumber",
Usage: "Max checkpoint number which will be stored",
Value: pathdb.DefaultMaxCheckpointNumber,
Category: flags.StateCategory,
}
StateHistoryFlag = &cli.Uint64Flag{
Name: "history.state",
Usage: "Number of recent blocks to retain state history for (default = 90,000 blocks, 0 = entire chain)",
Expand Down Expand Up @@ -1874,6 +1886,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.IsSet(ProposeBlockIntervalFlag.Name) {
cfg.ProposeBlockInterval = ctx.Uint64(ProposeBlockIntervalFlag.Name)
}
if ctx.IsSet(EnableCheckpointFlag.Name) {
cfg.EnableCheckpoint = ctx.Bool(EnableCheckpointFlag.Name)
}
if ctx.IsSet(MaxCheckpointNumberFlag.Name) {
cfg.MaxCheckpointNumber = ctx.Uint64(MaxCheckpointNumberFlag.Name)
}
if ctx.String(GCModeFlag.Name) == "archive" && cfg.TransactionHistory != 0 {
cfg.TransactionHistory = 0
log.Warn("Disabled transaction unindexing for archive node")
Expand Down
6 changes: 6 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ type CacheConfig struct {
StateScheme string // Scheme used to store ethereum states and merkle tree nodes on top
PathSyncFlush bool // Whether sync flush the trienodebuffer of pathdb to disk.
ProposeBlockInterval uint64 // Propose block to L1 block interval.
CheckpointDir string // Used to store checkpoints directory
EnableCheckpoint bool // Enable trie db checkpoint for get withdraw-contract proof
MaxCheckpointNumber uint64 // Max checkpoint number which will be stored
SnapshotNoBuild bool // Whether the background generation is allowed
SnapshotWait bool // Wait for snapshot construction on startup. TODO(karalabe): This is a dirty hack for testing, nuke it

Expand All @@ -169,6 +172,9 @@ func (c *CacheConfig) triedbConfig() *trie.Config {
CleanCacheSize: c.TrieCleanLimit * 1024 * 1024,
DirtyCacheSize: c.TrieDirtyLimit * 1024 * 1024,
ProposeBlockInterval: c.ProposeBlockInterval,
CheckpointDir: c.CheckpointDir,
EnableCheckpoint: c.EnableCheckpoint,
MaxCheckpointNumber: c.MaxCheckpointNumber,
}
}
return config
Expand Down
4 changes: 4 additions & 0 deletions core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,3 +664,7 @@ func ReadChainMetadata(db ethdb.KeyValueStore) [][]string {
}
return data
}

func (db *freezerdb) NewCheckpoint(destDir string) error {
return errors.New("freezerdb checkpoint is unsupported")
}
6 changes: 6 additions & 0 deletions core/rawdb/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package rawdb

import (
"errors"

"github.com/ethereum/go-ethereum/ethdb"
)

Expand All @@ -35,6 +37,10 @@ func NewTable(db ethdb.Database, prefix string) ethdb.Database {
}
}

func (t *table) NewCheckpoint(destDir string) error {
return errors.New("table checkpoint is unsupported")
}

// Close is a noop to implement the Database interface.
func (t *table) Close() error {
return nil
Expand Down
4 changes: 4 additions & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/trie/triedb/pathdb"
)

// Config contains the configuration options of the ETH protocol.
Expand Down Expand Up @@ -208,6 +209,9 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
TrieCommitInterval: config.TrieCommitInterval,
PathSyncFlush: config.PathSyncFlush,
ProposeBlockInterval: config.ProposeBlockInterval,
EnableCheckpoint: config.EnableCheckpoint,
MaxCheckpointNumber: config.MaxCheckpointNumber,
CheckpointDir: stack.ResolvePath(pathdb.DefaultCheckpointDir),
}
)
// Override the chain config with provided settings.
Expand Down
2 changes: 2 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ type Config struct {
StateScheme string `toml:",omitempty"`
PathSyncFlush bool `toml:",omitempty"` // State scheme used to store ethereum state and merkle trie nodes on top
ProposeBlockInterval uint64 `toml:",omitempty"` // Keep the same with op-proposer propose block interval
EnableCheckpoint bool `toml:",omitempty"` // Enable trie db checkpoint for get withdraw-contract proof
MaxCheckpointNumber uint64 `toml:",omitempty"` // Max checkpoint number which will be stored

// RequiredBlocks is a set of block number -> hash mappings which must be in the
// canonical chain of all remote peers. Setting the option makes geth verify the
Expand Down
18 changes: 14 additions & 4 deletions eth/ethconfig/gen_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions ethdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type KeyValueStore interface {
Iteratee
Compacter
Snapshotter
Checkpointer
io.Closer
}

Expand Down Expand Up @@ -149,6 +150,10 @@ type AncientStater interface {
AncientDatadir() (string, error)
}

type Checkpointer interface {
NewCheckpoint(destDir string) error
}

// Reader contains the methods required to read data from both key-value as well as
// immutable ancient data.
type Reader interface {
Expand Down Expand Up @@ -188,5 +193,6 @@ type Database interface {
Stater
Compacter
Snapshotter
Checkpointer
io.Closer
}
4 changes: 4 additions & 0 deletions ethdb/leveldb/leveldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,7 @@ func (snap *snapshot) Get(key []byte) ([]byte, error) {
func (snap *snapshot) Release() {
snap.db.Release()
}

func (db *Database) NewCheckpoint(destDir string) error {
return errors.New("leveldb checkpoint is unsupported")
}
4 changes: 4 additions & 0 deletions ethdb/memorydb/memorydb.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,7 @@ func (snap *snapshot) Release() {

snap.db = nil
}

func (db *Database) NewCheckpoint(destDir string) error {
return errors.New("memory db checkpoint is unsupported")
}
7 changes: 7 additions & 0 deletions ethdb/pebble/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,3 +667,10 @@ func (iter *pebbleIterator) Value() []byte {
// Release releases associated resources. Release should always succeed and can
// be called multiple times without causing error.
func (iter *pebbleIterator) Release() { iter.iter.Close() }

func (d *Database) NewCheckpoint(destDir string) error {
var opts []pebble.CheckpointOption
opt := pebble.WithFlushedWAL()
opts = append(opts, opt)
return d.db.Checkpoint(destDir, opts...)
}
6 changes: 6 additions & 0 deletions ethdb/remotedb/remotedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
package remotedb

import (
"errors"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/rpc"
Expand Down Expand Up @@ -152,3 +154,7 @@ func New(client *rpc.Client) ethdb.Database {
remote: client,
}
}

func (db *Database) NewCheckpoint(destDir string) error {
return errors.New("remotedb checkpoint is unsupported")
}
Loading

0 comments on commit 7c7f9aa

Please sign in to comment.