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

maindb v4 #868

Open
wants to merge 42 commits into
base: feat/db
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a14e1d4
cmd/thor: update instance dir to v4
qianbin Dec 14, 2023
c763d81
trie: implement varint-prefix coder
qianbin Jan 9, 2024
8244e7e
deps: add github.com/qianbin/drlp
qianbin Jan 9, 2024
cfda3d1
trie: implement appendHexToCompact & compactLen
qianbin Jan 9, 2024
c3604d9
trie: temporarily remove merkle proof stuff
qianbin Jan 9, 2024
9c9c4b5
trie: many changes
qianbin Jan 11, 2024
dc608ab
trie: optimize full-node encoding/decoding
qianbin Jan 18, 2024
2c1d769
trie: tweak shortnode encoding
qianbin Jan 19, 2024
60476fb
muxdb: move engine pkg
qianbin Jan 19, 2024
e1060bb
trie: add Version() method for node interface
qianbin Jan 26, 2024
32fc127
muxdb: refactor due to trie updates and:
qianbin Jan 26, 2024
8c1d747
chain: a lot of changes
qianbin Jan 28, 2024
4f65e60
state: changes due to update of trie
qianbin Feb 1, 2024
ea6f347
lowrlp: remove this pkg
qianbin Feb 1, 2024
fa7f182
txpool: changes due to underlying pkg update
qianbin Feb 2, 2024
c997523
genesis: changes due to underlying pkg update
qianbin Feb 2, 2024
58f4696
consensus: changes due to underlying pkg update
qianbin Feb 2, 2024
b379548
builtin: changes due to underlying pkg update
qianbin Feb 2, 2024
ca14559
runtime: changes due to underlying pkg update
qianbin Feb 2, 2024
47641c6
api: changes due to underlying pkg update
qianbin Feb 2, 2024
81d037d
cmd/thor/pruner: rename pkg optimizer to pruner
qianbin Feb 2, 2024
462d027
cmd/thor: changes due to underlying pkg update
qianbin Feb 2, 2024
d13612d
muxdb: abandon leaf filter
qianbin Feb 12, 2024
ee8042f
cmd/thor/pruner: use smaller period when nearly synced
qianbin Feb 12, 2024
3051036
muxdb: improve trie node path encoding
qianbin Feb 12, 2024
dfa1449
trie: treat short nodes as standalone nodes when skipping hash
qianbin Feb 12, 2024
50950a5
cmd/thor: fix disablePrunerFlag not work
qianbin Feb 13, 2024
e451f8d
trie: improve refNode encoding/decoding
qianbin Feb 19, 2024
b2ddde5
muxdb: improve history node key encoding
qianbin Feb 19, 2024
e3dda9f
cmd/thor: adjust pruner parameters
qianbin Feb 20, 2024
ab527e0
build: fix test cases
qianbin Feb 21, 2024
0cbf4bc
lint: fix lint error
qianbin Feb 21, 2024
b82050c
muxdb: fix ver encoding in node blob cache
qianbin Feb 28, 2024
64e43b8
muxdb: add test cases for cache
qianbin Feb 28, 2024
2ee8592
runtime: fix test compile error
qianbin Mar 25, 2024
960f4f0
make build and test pass after rebase
libotony Aug 6, 2024
ef814c0
add back pruner tests
libotony Oct 25, 2024
00c3760
add tests for node encoding
libotony Nov 1, 2024
d847f08
minor typo
libotony Nov 1, 2024
bf6193d
update named store space prefix
libotony Nov 5, 2024
a83ab16
add more tests
libotony Nov 6, 2024
3e5f529
fix block summary in repo
libotony Nov 6, 2024
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 api/accounts/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func packTx(repo *chain.Repository, stater *state.Stater, transaction *tx.Transa
if _, err := stage.Commit(); err != nil {
t.Fatal(err)
}
if err := repo.AddBlock(b, receipts, 0); err != nil {
if err := repo.AddBlock(b, receipts, 0, false); err != nil {
t.Fatal(err)
}
if err := repo.SetBestBlockID(b.Header().ID()); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion api/blocks/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func initBlockServer(t *testing.T) {
if _, err := stage.Commit(); err != nil {
t.Fatal(err)
}
if err := repo.AddBlock(block, receipts, 0); err != nil {
if err := repo.AddBlock(block, receipts, 0, false); err != nil {
t.Fatal(err)
}
if err := repo.SetBestBlockID(block.Header().ID()); err != nil {
Expand Down
7 changes: 4 additions & 3 deletions api/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/vechain/thor/v2/test/datagen"
"github.com/vechain/thor/v2/thor"
"github.com/vechain/thor/v2/tracers/logger"
"github.com/vechain/thor/v2/trie"
"github.com/vechain/thor/v2/tx"

// Force-load the tracer native engines to trigger registration
Expand Down Expand Up @@ -95,7 +96,7 @@ func TestDebug(t *testing.T) {

func TestStorageRangeFunc(t *testing.T) {
db := muxdb.NewMem()
state := state.New(db, thor.Bytes32{}, 0, 0, 0)
state := state.New(db, trie.Root{})

// Create an account and set storage values
addr := thor.BytesToAddress([]byte("account1"))
Expand Down Expand Up @@ -125,7 +126,7 @@ func TestStorageRangeFunc(t *testing.T) {

func TestStorageRangeMaxResult(t *testing.T) {
db := muxdb.NewMem()
state := state.New(db, thor.Bytes32{}, 0, 0, 0)
state := state.New(db, trie.Root{})

addr := thor.BytesToAddress([]byte("account1"))
for i := 0; i < 1001; i++ {
Expand Down Expand Up @@ -569,7 +570,7 @@ func initDebugServer(t *testing.T) {
if _, err := stage.Commit(); err != nil {
t.Fatal(err)
}
if err := repo.AddBlock(b, receipts, 0); err != nil {
if err := repo.AddBlock(b, receipts, 0, false); err != nil {
t.Fatal(err)
}
if err := repo.SetBestBlockID(b.Header().ID()); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion api/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestMetricsMiddleware(t *testing.T) {
repo, _ := chain.NewRepository(db, b)

// inject some invalid data to db
data := db.NewStore("chain.data")
data := db.NewStore("chain.hdr")
var blkID thor.Bytes32
rand.Read(blkID[:])
data.Put(blkID[:], []byte("invalid data"))
Expand Down
2 changes: 1 addition & 1 deletion api/subscriptions/block_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func initChain(t *testing.T) (*chain.Repository, []*block.Block, *txpool.TxPool)
t.Fatal(err)
}
insertMockOutputEvent(receipts)
if err := repo.AddBlock(blk, receipts, 0); err != nil {
if err := repo.AddBlock(blk, receipts, 0, false); err != nil {
t.Fatal(err)
}
if err := repo.SetBestBlockID(blk.Header().ID()); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion api/subscriptions/pending_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func addNewBlock(repo *chain.Repository, stater *state.Stater, b0 *block.Block,
if _, err := stage.Commit(); err != nil {
t.Fatal(err)
}
if err := repo.AddBlock(blk, receipts, 0); err != nil {
if err := repo.AddBlock(blk, receipts, 0, false); err != nil {
t.Fatal(err)
}
if err := repo.SetBestBlockID(blk.Header().ID()); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion api/subscriptions/subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func initChainMultipleBlocks(t *testing.T, blockCount int) (*chain.Repository, [
if _, err := stage.Commit(); err != nil {
t.Fatal(err)
}
if err := repo.AddBlock(blk, receipts, 0); err != nil {
if err := repo.AddBlock(blk, receipts, 0, false); err != nil {
t.Fatal(err)
}
if err := repo.SetBestBlockID(blk.Header().ID()); err != nil {
Expand Down
16 changes: 8 additions & 8 deletions api/transactions/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (t *Transactions) getRawTransaction(txID thor.Bytes32, head thor.Bytes32, a
return nil, err
}

summary, err := t.repo.GetBlockSummary(meta.BlockID)
header, err := chain.GetBlockHeader(meta.BlockNum)
if err != nil {
return nil, err
}
Expand All @@ -62,9 +62,9 @@ func (t *Transactions) getRawTransaction(txID thor.Bytes32, head thor.Bytes32, a
return &rawTransaction{
RawTx: RawTx{hexutil.Encode(raw)},
Meta: &TxMeta{
BlockID: summary.Header.ID(),
BlockNumber: summary.Header.Number(),
BlockTimestamp: summary.Header.Timestamp(),
BlockID: header.ID(),
BlockNumber: header.Number(),
BlockTimestamp: header.Timestamp(),
},
}, nil
}
Expand All @@ -84,11 +84,11 @@ func (t *Transactions) getTransactionByID(txID thor.Bytes32, head thor.Bytes32,
return nil, err
}

summary, err := t.repo.GetBlockSummary(meta.BlockID)
header, err := chain.GetBlockHeader(meta.BlockNum)
if err != nil {
return nil, err
}
return convertTransaction(tx, summary.Header), nil
return convertTransaction(tx, header), nil
}

// GetTransactionReceiptByID get tx's receipt
Expand All @@ -107,12 +107,12 @@ func (t *Transactions) getTransactionReceiptByID(txID thor.Bytes32, head thor.By
return nil, err
}

summary, err := t.repo.GetBlockSummary(meta.BlockID)
header, err := chain.GetBlockHeader(meta.BlockNum)
if err != nil {
return nil, err
}

return convertReceipt(receipt, summary.Header, tx)
return convertReceipt(receipt, header, tx)
}
func (t *Transactions) handleSendTransaction(w http.ResponseWriter, req *http.Request) error {
var rawTx *RawTx
Expand Down
2 changes: 1 addition & 1 deletion api/transactions/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func initTransactionServer(t *testing.T) {
if _, err := stage.Commit(); err != nil {
t.Fatal(err)
}
if err := repo.AddBlock(b, receipts, 0); err != nil {
if err := repo.AddBlock(b, receipts, 0, false); err != nil {
t.Fatal(err)
}
if err := repo.SetBestBlockID(b.Header().ID()); err != nil {
Expand Down
5 changes: 2 additions & 3 deletions api/utils/revisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,21 @@ func GetSummaryAndState(rev *Revision, repo *chain.Repository, bft bft.Committer
mocked := builder.Build()

// state is also reused from the parent block
st := stater.NewState(best.Header.StateRoot(), best.Header.Number(), best.Conflicts, best.SteadyNum)
st := stater.NewState(best.Root())

// rebuild the block summary with the next header (mocked) AND the best block status
return &chain.BlockSummary{
Header: mocked.Header(),
Txs: best.Txs,
Size: uint64(mocked.Size()),
Conflicts: best.Conflicts,
SteadyNum: best.SteadyNum,
}, st, nil
}
sum, err := GetSummary(rev, repo, bft)
if err != nil {
return nil, nil, err
}

st := stater.NewState(sum.Header.StateRoot(), sum.Header.Number(), sum.Conflicts, sum.SteadyNum)
st := stater.NewState(sum.Root())
return sum, st, nil
}
2 changes: 1 addition & 1 deletion bft/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func (engine *Engine) findCheckpointByQuality(target uint32, finalized, headID t
}

func (engine *Engine) getMaxBlockProposers(sum *chain.BlockSummary) (uint64, error) {
state := engine.stater.NewState(sum.Header.StateRoot(), sum.Header.Number(), sum.Conflicts, sum.SteadyNum)
state := engine.stater.NewState(sum.Root())
params, err := builtin.Params.Native(state).Get(thor.KeyMaxBlockProposers)
if err != nil {
return 0, err
Expand Down
2 changes: 1 addition & 1 deletion bft/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (test *TestBFT) newBlock(parentSummary *chain.BlockSummary, master genesis.
return nil, err
}

if err = test.repo.AddBlock(b, nil, conflicts); err != nil {
if err = test.repo.AddBlock(b, nil, conflicts, false); err != nil {
return nil, err
}

Expand Down
3 changes: 2 additions & 1 deletion builtin/authority/authority_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/vechain/thor/v2/muxdb"
"github.com/vechain/thor/v2/state"
"github.com/vechain/thor/v2/thor"
"github.com/vechain/thor/v2/trie"
)

func M(a ...interface{}) []interface{} {
Expand All @@ -21,7 +22,7 @@ func M(a ...interface{}) []interface{} {

func TestAuthority(t *testing.T) {
db := muxdb.NewMem()
st := state.New(db, thor.Bytes32{}, 0, 0, 0)
st := state.New(db, trie.Root{})

p1 := thor.BytesToAddress([]byte("p1"))
p2 := thor.BytesToAddress([]byte("p2"))
Expand Down
15 changes: 8 additions & 7 deletions builtin/energy/energy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/vechain/thor/v2/muxdb"
"github.com/vechain/thor/v2/state"
"github.com/vechain/thor/v2/thor"
"github.com/vechain/thor/v2/trie"
)

func M(a ...interface{}) []interface{} {
Expand All @@ -21,7 +22,7 @@ func M(a ...interface{}) []interface{} {

func TestEnergy(t *testing.T) {
db := muxdb.NewMem()
st := state.New(db, thor.Bytes32{}, 0, 0, 0)
st := state.New(db, trie.Root{})

acc := thor.BytesToAddress([]byte("a1"))

Expand All @@ -46,7 +47,7 @@ func TestEnergy(t *testing.T) {

func TestInitialSupply(t *testing.T) {
db := muxdb.NewMem()
st := state.New(db, thor.Bytes32{}, 0, 0, 0)
st := state.New(db, trie.Root{})

eng := New(thor.BytesToAddress([]byte("eng")), st, 0)

Expand All @@ -64,7 +65,7 @@ func TestInitialSupply(t *testing.T) {

func TestInitialSupplyError(t *testing.T) {
db := muxdb.NewMem()
st := state.New(db, thor.Bytes32{}, 0, 0, 0)
st := state.New(db, trie.Root{})

eng := New(thor.BytesToAddress([]byte("a1")), st, 0)

Expand All @@ -78,7 +79,7 @@ func TestInitialSupplyError(t *testing.T) {

func TestTotalSupply(t *testing.T) {
db := muxdb.NewMem()
st := state.New(db, thor.Bytes32{}, 0, 0, 0)
st := state.New(db, trie.Root{})

eng := New(thor.BytesToAddress([]byte("eng")), st, 0)

Expand All @@ -92,7 +93,7 @@ func TestTotalSupply(t *testing.T) {

func TestTokenTotalSupply(t *testing.T) {
db := muxdb.NewMem()
st := state.New(db, thor.Bytes32{}, 0, 0, 0)
st := state.New(db, trie.Root{})

eng := New(thor.BytesToAddress([]byte("eng")), st, 0)

Expand All @@ -106,7 +107,7 @@ func TestTokenTotalSupply(t *testing.T) {

func TestTotalBurned(t *testing.T) {
db := muxdb.NewMem()
st := state.New(db, thor.Bytes32{}, 0, 0, 0)
st := state.New(db, trie.Root{})

eng := New(thor.BytesToAddress([]byte("eng")), st, 0)

Expand All @@ -120,7 +121,7 @@ func TestTotalBurned(t *testing.T) {

func TestEnergyGrowth(t *testing.T) {
db := muxdb.NewMem()
st := state.New(db, thor.Bytes32{}, 0, 0, 0)
st := state.New(db, trie.Root{})

acc := thor.BytesToAddress([]byte("a1"))

Expand Down
3 changes: 2 additions & 1 deletion builtin/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/vechain/thor/v2/runtime"
"github.com/vechain/thor/v2/state"
"github.com/vechain/thor/v2/thor"
"github.com/vechain/thor/v2/trie"
"github.com/vechain/thor/v2/tx"
"github.com/vechain/thor/v2/xenv"
)
Expand Down Expand Up @@ -73,7 +74,7 @@ func initExectorTest() *ctest {
})

repo, _ := chain.NewRepository(db, b0)
st := state.New(db, b0.Header().StateRoot(), 0, 0, 0)
st := state.New(db, trie.Root{Hash: b0.Header().StateRoot()})
chain := repo.NewChain(b0.Header().ID())

rt := runtime.New(chain, st, &xenv.BlockContext{Time: uint64(time.Now().Unix())}, thor.NoFork)
Expand Down
Loading
Loading