Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
96bbca5
Fix pruning with an arbitrary target root
PlasmaPower Dec 7, 2022
1e3c069
Merge branch 'master' into arbitrary-prune-point
PlasmaPower Dec 14, 2022
e403d14
Support pruning to multiple state roots
PlasmaPower Dec 14, 2022
52ddf7f
Free lastSnaptree early
PlasmaPower Dec 15, 2022
fb81ff4
Fix missing headSnaptree calculation
PlasmaPower Dec 15, 2022
54c3ca9
Re-fix calling Cap on a disk layer snapshot
PlasmaPower Dec 15, 2022
6e60560
Add support for non-snapshot based pruning
PlasmaPower Dec 15, 2022
5fcf71b
Fix missing genesis state case
PlasmaPower Dec 15, 2022
197331f
Address remaining TODOs
PlasmaPower Dec 22, 2022
1e780fd
Improve removeOtherRoots
PlasmaPower Dec 22, 2022
ae27026
Fix waiting for error and improve logging
PlasmaPower Dec 22, 2022
bc1b10b
Only traverse storage trie if storage is non-empty
PlasmaPower Dec 23, 2022
3da051a
Add log message when done removing old state roots
PlasmaPower Dec 24, 2022
43e8c2f
Store bloom filter roots in the file content
PlasmaPower Dec 28, 2022
5521226
Fix reading in a state bloom from file
PlasmaPower Dec 29, 2022
2dfaad1
Merge pull request #189 from OffchainLabs/bloom-file-roots
PlasmaPower Dec 29, 2022
f9db2af
Merge branch 'master' into arbitrary-prune-point
PlasmaPower Jan 11, 2023
080c490
Merge branch 'master' into arbitrary-prune-point
PlasmaPower Jan 26, 2023
2ed3220
Merge branch 'master' into arbitrary-prune-point
PlasmaPower Mar 30, 2023
7ba1099
Merge branch 'master' into arbitrary-prune-point
PlasmaPower Apr 13, 2023
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
10 changes: 7 additions & 3 deletions cmd/geth/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,19 @@ func pruneState(ctx *cli.Context) error {
log.Error("Too many arguments given")
return errors.New("too many arguments")
}
var targetRoot common.Hash
var targetRoots []common.Hash
if ctx.NArg() == 1 {
targetRoot, err = parseRoot(ctx.Args().First())
root, err := parseRoot(ctx.Args().First())
if err != nil {
log.Error("Failed to resolve state root", "err", err)
return err
}
targetRoots = append(targetRoots, root)
} else {
// Prune to the last snapshot
targetRoots = append(targetRoots, common.Hash{})
}
if err = pruner.Prune(targetRoot); err != nil {
if err = pruner.Prune(targetRoots); err != nil {
log.Error("Failed to prune state", "err", err)
return err
}
Expand Down
7 changes: 7 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,13 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, root common.Hash, repair bo
// if the historical chain pruning is enabled. In that case the logic
// needs to be improved here.
if !bc.HasState(bc.genesisBlock.Root()) {
// Arbitrum: we have a later block with state; use that instead.
if lastFullBlock != 0 {
blockNumber = lastFullBlock
newHeadBlock = bc.GetBlock(lastFullBlockHash, lastFullBlock)
log.Debug("Rewound to block with state but not snapshot", "number", newHeadBlock.NumberU64(), "hash", newHeadBlock.Hash())
break
}
if err := CommitGenesisState(bc.db, bc.genesisBlock.Hash()); err != nil {
log.Crit("Failed to commit genesis state", "err", err)
}
Expand Down
57 changes: 48 additions & 9 deletions core/state/pruner/bloom.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
package pruner

import (
"bufio"
"encoding/binary"
"errors"
"fmt"
"io"
"os"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
bloomfilter "github.com/holiman/bloomfilter/v2"
)

Expand Down Expand Up @@ -73,27 +77,54 @@ func newStateBloomWithSize(size uint64) (*stateBloom, error) {

// NewStateBloomFromDisk loads the state bloom from the given file.
// In this case the assumption is held the bloom filter is complete.
func NewStateBloomFromDisk(filename string) (*stateBloom, error) {
bloom, _, err := bloomfilter.ReadFile(filename)
func NewStateBloomFromDisk(filename string) (*stateBloom, []common.Hash, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
return nil, nil, err
}
return &stateBloom{bloom: bloom}, nil
defer f.Close()
r := bufio.NewReader(f)
version := []byte{0}
_, err = io.ReadFull(r, version)
if err != nil {
return nil, nil, err
}
if version[0] != 0 {
return nil, nil, fmt.Errorf("unknown state bloom filter version %v", version[0])
}
var roots []common.Hash
err = rlp.Decode(r, &roots)
if err != nil {
return nil, nil, err
}
bloom, _, err := bloomfilter.ReadFrom(r)
if err != nil {
return nil, nil, err
}
return &stateBloom{bloom: bloom}, roots, nil
}

// Commit flushes the bloom filter content into the disk and marks the bloom
// as complete.
func (bloom *stateBloom) Commit(filename, tempname string) error {
// Write the bloom out into a temporary file
_, err := bloom.bloom.WriteFile(tempname)
func (bloom *stateBloom) Commit(filename, tempname string, roots []common.Hash) error {
f, err := os.OpenFile(tempname, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
return err
}
// Ensure the file is synced to disk
f, err := os.OpenFile(tempname, os.O_RDWR, 0666)
_, err = f.Write([]byte{0}) // version
if err != nil {
return err
}
err = rlp.Encode(f, roots)
if err != nil {
return err
}
// Write the bloom out into a temporary file
_, err = bloom.bloom.WriteTo(f)
if err != nil {
return err
}
// Ensure the file is synced to disk
if err := f.Sync(); err != nil {
f.Close()
return err
Expand Down Expand Up @@ -130,3 +161,11 @@ func (bloom *stateBloom) Delete(key []byte) error { panic("not supported") }
func (bloom *stateBloom) Contain(key []byte) (bool, error) {
return bloom.bloom.Contains(stateBloomHasher(key)), nil
}

func (bloom *stateBloom) FalsePosititveProbability() float64 {
return bloom.bloom.FalsePosititveProbability()
}

func (bloom *stateBloom) Size() uint64 {
return bloom.bloom.M()
}
Loading