all: new empty trie with types.EmptyRootHash instead of null (#27230)

This commit is contained in:
Daniel Liu 2025-02-07 12:29:23 +08:00
parent 65ea1c517f
commit ebb2c3b2ea
35 changed files with 110 additions and 86 deletions

View file

@ -8,6 +8,7 @@ import (
"github.com/XinFinOrg/XDPoSChain/XDCx/tradingstate" "github.com/XinFinOrg/XDPoSChain/XDCx/tradingstate"
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/rawdb" "github.com/XinFinOrg/XDPoSChain/core/rawdb"
"github.com/XinFinOrg/XDPoSChain/core/types"
) )
func Test_getCancelFeeV1(t *testing.T) { func Test_getCancelFeeV1(t *testing.T) {
@ -92,7 +93,7 @@ func Test_getCancelFee(t *testing.T) {
XDCx := New(&DefaultConfig) XDCx := New(&DefaultConfig)
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
stateCache := tradingstate.NewDatabase(db) stateCache := tradingstate.NewDatabase(db)
tradingStateDb, _ := tradingstate.New(common.Hash{}, stateCache) tradingStateDb, _ := tradingstate.New(types.EmptyRootHash, stateCache)
testTokenA := common.HexToAddress("0x1000000000000000000000000000000000000002") testTokenA := common.HexToAddress("0x1000000000000000000000000000000000000002")
testTokenB := common.HexToAddress("0x1100000000000000000000000000000000000003") testTokenB := common.HexToAddress("0x1100000000000000000000000000000000000003")

View file

@ -2,19 +2,21 @@ package tradingstate
import ( import (
"fmt" "fmt"
"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
"math/big" "math/big"
"math/rand" "math/rand"
"testing" "testing"
"time" "time"
"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
"github.com/XinFinOrg/XDPoSChain/core/types"
) )
func TestXDCxTrieTest(t *testing.T) { func TestXDCxTrieTest(t *testing.T) {
t.SkipNow() t.SkipNow()
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
stateCache := NewDatabase(db) stateCache := NewDatabase(db)
trie, _ := stateCache.OpenStorageTrie(EmptyHash, EmptyHash) trie, _ := stateCache.OpenStorageTrie(EmptyHash, types.EmptyRootHash)
max := 1000000 max := 1000000
for i := 1; i < max; i++ { for i := 1; i < max; i++ {
k := common.BigToHash(big.NewInt(int64(i))).Bytes() k := common.BigToHash(big.NewInt(int64(i))).Bytes()

View file

@ -23,6 +23,7 @@ import (
"math/big" "math/big"
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/rlp" "github.com/XinFinOrg/XDPoSChain/rlp"
"github.com/XinFinOrg/XDPoSChain/trie" "github.com/XinFinOrg/XDPoSChain/trie"
) )
@ -80,7 +81,7 @@ func (s *stateLendingBook) getTrie(db Database) Trie {
var err error var err error
s.trie, err = db.OpenStorageTrie(s.lendingBook, s.data.Root) s.trie, err = db.OpenStorageTrie(s.lendingBook, s.data.Root)
if err != nil { if err != nil {
s.trie, _ = db.OpenStorageTrie(s.price, EmptyHash) s.trie, _ = db.OpenStorageTrie(s.price, types.EmptyRootHash)
s.setError(fmt.Errorf("can't create storage trie: %v", err)) s.setError(fmt.Errorf("can't create storage trie: %v", err))
} }
} }

View file

@ -22,6 +22,7 @@ import (
"math/big" "math/big"
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/log" "github.com/XinFinOrg/XDPoSChain/log"
"github.com/XinFinOrg/XDPoSChain/rlp" "github.com/XinFinOrg/XDPoSChain/rlp"
"github.com/XinFinOrg/XDPoSChain/trie" "github.com/XinFinOrg/XDPoSChain/trie"
@ -103,7 +104,7 @@ func (l *liquidationPriceState) getTrie(db Database) Trie {
var err error var err error
l.trie, err = db.OpenStorageTrie(l.liquidationPrice, l.data.Root) l.trie, err = db.OpenStorageTrie(l.liquidationPrice, l.data.Root)
if err != nil { if err != nil {
l.trie, _ = db.OpenStorageTrie(l.liquidationPrice, EmptyHash) l.trie, _ = db.OpenStorageTrie(l.liquidationPrice, types.EmptyRootHash)
l.setError(fmt.Errorf("can't create storage trie: %v", err)) l.setError(fmt.Errorf("can't create storage trie: %v", err))
} }
} }

View file

@ -23,6 +23,7 @@ import (
"math/big" "math/big"
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/rlp" "github.com/XinFinOrg/XDPoSChain/rlp"
) )
@ -91,7 +92,7 @@ func (c *stateOrderList) getTrie(db Database) Trie {
var err error var err error
c.trie, err = db.OpenStorageTrie(c.price, c.data.Root) c.trie, err = db.OpenStorageTrie(c.price, c.data.Root)
if err != nil { if err != nil {
c.trie, _ = db.OpenStorageTrie(c.price, EmptyHash) c.trie, _ = db.OpenStorageTrie(c.price, types.EmptyRootHash)
c.setError(fmt.Errorf("can't create storage trie: %v", err)) c.setError(fmt.Errorf("can't create storage trie: %v", err))
} }
} }

View file

@ -22,6 +22,7 @@ import (
"math/big" "math/big"
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/log" "github.com/XinFinOrg/XDPoSChain/log"
"github.com/XinFinOrg/XDPoSChain/rlp" "github.com/XinFinOrg/XDPoSChain/rlp"
) )
@ -135,7 +136,7 @@ func (te *tradingExchanges) getAsksTrie(db Database) Trie {
var err error var err error
te.asksTrie, err = db.OpenStorageTrie(te.orderBookHash, te.data.AskRoot) te.asksTrie, err = db.OpenStorageTrie(te.orderBookHash, te.data.AskRoot)
if err != nil { if err != nil {
te.asksTrie, _ = db.OpenStorageTrie(te.orderBookHash, EmptyHash) te.asksTrie, _ = db.OpenStorageTrie(te.orderBookHash, types.EmptyRootHash)
te.setError(fmt.Errorf("can't create asks trie: %v", err)) te.setError(fmt.Errorf("can't create asks trie: %v", err))
} }
} }
@ -147,7 +148,7 @@ func (te *tradingExchanges) getOrdersTrie(db Database) Trie {
var err error var err error
te.ordersTrie, err = db.OpenStorageTrie(te.orderBookHash, te.data.OrderRoot) te.ordersTrie, err = db.OpenStorageTrie(te.orderBookHash, te.data.OrderRoot)
if err != nil { if err != nil {
te.ordersTrie, _ = db.OpenStorageTrie(te.orderBookHash, EmptyHash) te.ordersTrie, _ = db.OpenStorageTrie(te.orderBookHash, types.EmptyRootHash)
te.setError(fmt.Errorf("can't create asks trie: %v", err)) te.setError(fmt.Errorf("can't create asks trie: %v", err))
} }
} }
@ -265,7 +266,7 @@ func (te *tradingExchanges) getBidsTrie(db Database) Trie {
var err error var err error
te.bidsTrie, err = db.OpenStorageTrie(te.orderBookHash, te.data.BidRoot) te.bidsTrie, err = db.OpenStorageTrie(te.orderBookHash, te.data.BidRoot)
if err != nil { if err != nil {
te.bidsTrie, _ = db.OpenStorageTrie(te.orderBookHash, EmptyHash) te.bidsTrie, _ = db.OpenStorageTrie(te.orderBookHash, types.EmptyRootHash)
te.setError(fmt.Errorf("can't create bids trie: %v", err)) te.setError(fmt.Errorf("can't create bids trie: %v", err))
} }
} }
@ -636,7 +637,7 @@ func (t *tradingExchanges) getLiquidationPriceTrie(db Database) Trie {
var err error var err error
t.liquidationPriceTrie, err = db.OpenStorageTrie(t.orderBookHash, t.data.LiquidationPriceRoot) t.liquidationPriceTrie, err = db.OpenStorageTrie(t.orderBookHash, t.data.LiquidationPriceRoot)
if err != nil { if err != nil {
t.liquidationPriceTrie, _ = db.OpenStorageTrie(t.orderBookHash, EmptyHash) t.liquidationPriceTrie, _ = db.OpenStorageTrie(t.orderBookHash, types.EmptyRootHash)
t.setError(fmt.Errorf("can't create liquidation liquidationPrice trie: %v", err)) t.setError(fmt.Errorf("can't create liquidation liquidationPrice trie: %v", err))
} }
} }

View file

@ -24,6 +24,7 @@ import (
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/rawdb" "github.com/XinFinOrg/XDPoSChain/core/rawdb"
"github.com/XinFinOrg/XDPoSChain/core/types"
) )
func TestEchangeStates(t *testing.T) { func TestEchangeStates(t *testing.T) {
@ -42,7 +43,7 @@ func TestEchangeStates(t *testing.T) {
// Create an empty statedb database // Create an empty statedb database
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
stateCache := NewDatabase(db) stateCache := NewDatabase(db)
statedb, _ := New(common.Hash{}, stateCache) statedb, _ := New(types.EmptyRootHash, stateCache)
// Update it with some exchanges // Update it with some exchanges
for i := 0; i < numberOrder; i++ { for i := 0; i < numberOrder; i++ {
@ -172,7 +173,7 @@ func TestRevertStates(t *testing.T) {
// Create an empty statedb database // Create an empty statedb database
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
stateCache := NewDatabase(db) stateCache := NewDatabase(db)
statedb, _ := New(common.Hash{}, stateCache) statedb, _ := New(types.EmptyRootHash, stateCache)
// Update it with some exchanges // Update it with some exchanges
for i := 0; i < numberOrder; i++ { for i := 0; i < numberOrder; i++ {
@ -277,7 +278,7 @@ func TestDumpState(t *testing.T) {
// Create an empty statedb database // Create an empty statedb database
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
stateCache := NewDatabase(db) stateCache := NewDatabase(db)
statedb, _ := New(common.Hash{}, stateCache) statedb, _ := New(types.EmptyRootHash, stateCache)
for i := 0; i < len(orderItems); i++ { for i := 0; i < len(orderItems); i++ {
orderIdHash := common.BigToHash(new(big.Int).SetUint64(orderItems[i].OrderID)) orderIdHash := common.BigToHash(new(big.Int).SetUint64(orderItems[i].OrderID))

View file

@ -11,6 +11,7 @@ import (
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/rawdb" "github.com/XinFinOrg/XDPoSChain/core/rawdb"
"github.com/XinFinOrg/XDPoSChain/core/state" "github.com/XinFinOrg/XDPoSChain/core/state"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/crypto" "github.com/XinFinOrg/XDPoSChain/crypto"
"github.com/XinFinOrg/XDPoSChain/rpc" "github.com/XinFinOrg/XDPoSChain/rpc"
"golang.org/x/crypto/sha3" "golang.org/x/crypto/sha3"
@ -174,7 +175,7 @@ func SetCollateralDetail(statedb *state.StateDB, token common.Address, depositRa
func TestVerifyBalance(t *testing.T) { func TestVerifyBalance(t *testing.T) {
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
relayer := common.HexToAddress("0x0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e") relayer := common.HexToAddress("0x0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e")
uAddr := common.HexToAddress("0xDeE6238780f98c0ca2c2C28453149bEA49a3Abc9") uAddr := common.HexToAddress("0xDeE6238780f98c0ca2c2C28453149bEA49a3Abc9")
lendingToken := common.HexToAddress("0xd9bb01454c85247B2ef35BB5BE57384cC275a8cf") // USD lendingToken := common.HexToAddress("0xd9bb01454c85247B2ef35BB5BE57384cC275a8cf") // USD

View file

@ -23,6 +23,7 @@ import (
"math/big" "math/big"
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/rlp" "github.com/XinFinOrg/XDPoSChain/rlp"
) )
@ -79,7 +80,7 @@ func (il *itemListState) getTrie(db Database) Trie {
var err error var err error
il.trie, err = db.OpenStorageTrie(il.key, il.data.Root) il.trie, err = db.OpenStorageTrie(il.key, il.data.Root)
if err != nil { if err != nil {
il.trie, _ = db.OpenStorageTrie(il.key, EmptyHash) il.trie, _ = db.OpenStorageTrie(il.key, types.EmptyRootHash)
il.setError(fmt.Errorf("can't create storage trie: %v", err)) il.setError(fmt.Errorf("can't create storage trie: %v", err))
} }
} }

View file

@ -22,6 +22,7 @@ import (
"math/big" "math/big"
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/log" "github.com/XinFinOrg/XDPoSChain/log"
"github.com/XinFinOrg/XDPoSChain/rlp" "github.com/XinFinOrg/XDPoSChain/rlp"
) )
@ -128,7 +129,7 @@ func (le *lendingExchangeState) getLendingItemTrie(db Database) Trie {
var err error var err error
le.lendingItemTrie, err = db.OpenStorageTrie(le.lendingBook, le.data.LendingItemRoot) le.lendingItemTrie, err = db.OpenStorageTrie(le.lendingBook, le.data.LendingItemRoot)
if err != nil { if err != nil {
le.lendingItemTrie, _ = db.OpenStorageTrie(le.lendingBook, EmptyHash) le.lendingItemTrie, _ = db.OpenStorageTrie(le.lendingBook, types.EmptyRootHash)
le.setError(fmt.Errorf("can't create Lendings trie: %v", err)) le.setError(fmt.Errorf("can't create Lendings trie: %v", err))
} }
} }
@ -140,7 +141,7 @@ func (le *lendingExchangeState) getLendingTradeTrie(db Database) Trie {
var err error var err error
le.lendingTradeTrie, err = db.OpenStorageTrie(le.lendingBook, le.data.LendingTradeRoot) le.lendingTradeTrie, err = db.OpenStorageTrie(le.lendingBook, le.data.LendingTradeRoot)
if err != nil { if err != nil {
le.lendingTradeTrie, _ = db.OpenStorageTrie(le.lendingBook, EmptyHash) le.lendingTradeTrie, _ = db.OpenStorageTrie(le.lendingBook, types.EmptyRootHash)
le.setError(fmt.Errorf("can't create Lendings trie: %v", err)) le.setError(fmt.Errorf("can't create Lendings trie: %v", err))
} }
} }
@ -152,7 +153,7 @@ func (le *lendingExchangeState) getInvestingTrie(db Database) Trie {
var err error var err error
le.investingTrie, err = db.OpenStorageTrie(le.lendingBook, le.data.InvestingRoot) le.investingTrie, err = db.OpenStorageTrie(le.lendingBook, le.data.InvestingRoot)
if err != nil { if err != nil {
le.investingTrie, _ = db.OpenStorageTrie(le.lendingBook, EmptyHash) le.investingTrie, _ = db.OpenStorageTrie(le.lendingBook, types.EmptyRootHash)
le.setError(fmt.Errorf("can't create Lendings trie: %v", err)) le.setError(fmt.Errorf("can't create Lendings trie: %v", err))
} }
} }
@ -164,7 +165,7 @@ func (le *lendingExchangeState) getBorrowingTrie(db Database) Trie {
var err error var err error
le.borrowingTrie, err = db.OpenStorageTrie(le.lendingBook, le.data.BorrowingRoot) le.borrowingTrie, err = db.OpenStorageTrie(le.lendingBook, le.data.BorrowingRoot)
if err != nil { if err != nil {
le.borrowingTrie, _ = db.OpenStorageTrie(le.lendingBook, EmptyHash) le.borrowingTrie, _ = db.OpenStorageTrie(le.lendingBook, types.EmptyRootHash)
le.setError(fmt.Errorf("can't create bids trie: %v", err)) le.setError(fmt.Errorf("can't create bids trie: %v", err))
} }
} }
@ -176,7 +177,7 @@ func (le *lendingExchangeState) getLiquidationTimeTrie(db Database) Trie {
var err error var err error
le.liquidationTimeTrie, err = db.OpenStorageTrie(le.lendingBook, le.data.LiquidationTimeRoot) le.liquidationTimeTrie, err = db.OpenStorageTrie(le.lendingBook, le.data.LiquidationTimeRoot)
if err != nil { if err != nil {
le.liquidationTimeTrie, _ = db.OpenStorageTrie(le.lendingBook, EmptyHash) le.liquidationTimeTrie, _ = db.OpenStorageTrie(le.lendingBook, types.EmptyRootHash)
le.setError(fmt.Errorf("can't create bids trie: %v", err)) le.setError(fmt.Errorf("can't create bids trie: %v", err))
} }
} }

View file

@ -23,6 +23,7 @@ import (
"math/big" "math/big"
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/rlp" "github.com/XinFinOrg/XDPoSChain/rlp"
"github.com/XinFinOrg/XDPoSChain/trie" "github.com/XinFinOrg/XDPoSChain/trie"
) )
@ -78,7 +79,7 @@ func (lt *liquidationTimeState) getTrie(db Database) Trie {
var err error var err error
lt.trie, err = db.OpenStorageTrie(lt.lendingBook, lt.data.Root) lt.trie, err = db.OpenStorageTrie(lt.lendingBook, lt.data.Root)
if err != nil { if err != nil {
lt.trie, _ = db.OpenStorageTrie(lt.time, EmptyHash) lt.trie, _ = db.OpenStorageTrie(lt.time, types.EmptyRootHash)
lt.setError(fmt.Errorf("can't create storage trie: %v", err)) lt.setError(fmt.Errorf("can't create storage trie: %v", err))
} }
} }

View file

@ -23,6 +23,7 @@ import (
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/rawdb" "github.com/XinFinOrg/XDPoSChain/core/rawdb"
"github.com/XinFinOrg/XDPoSChain/core/types"
) )
func TestEchangeStates(t *testing.T) { func TestEchangeStates(t *testing.T) {
@ -40,7 +41,7 @@ func TestEchangeStates(t *testing.T) {
// Create an empty statedb database // Create an empty statedb database
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
stateCache := NewDatabase(db) stateCache := NewDatabase(db)
statedb, _ := New(common.Hash{}, stateCache) statedb, _ := New(types.EmptyRootHash, stateCache)
// Update it with some lenddinges // Update it with some lenddinges
for i := 0; i < numberOrder; i++ { for i := 0; i < numberOrder; i++ {
@ -127,7 +128,7 @@ func TestRevertStates(t *testing.T) {
// Create an empty statedb database // Create an empty statedb database
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
stateCache := NewDatabase(db) stateCache := NewDatabase(db)
statedb, _ := New(common.Hash{}, stateCache) statedb, _ := New(types.EmptyRootHash, stateCache)
// Update it with some lenddinges // Update it with some lenddinges
for i := 0; i < numberOrder; i++ { for i := 0; i < numberOrder; i++ {
@ -234,7 +235,7 @@ func TestDumpStates(t *testing.T) {
// Create an empty statedb database // Create an empty statedb database
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
stateCache := NewDatabase(db) stateCache := NewDatabase(db)
statedb, _ := New(common.Hash{}, stateCache) statedb, _ := New(types.EmptyRootHash, stateCache)
for i := 0; i < len(orderItems); i++ { for i := 0; i < len(orderItems); i++ {
orderIdHash := common.BigToHash(new(big.Int).SetUint64(orderItems[i].LendingId)) orderIdHash := common.BigToHash(new(big.Int).SetUint64(orderItems[i].LendingId))
statedb.InsertLendingItem(orderBook, orderIdHash, orderItems[i]) statedb.InsertLendingItem(orderBook, orderIdHash, orderItems[i])

View file

@ -10,6 +10,7 @@ import (
"github.com/XinFinOrg/XDPoSChain/XDCxlending/lendingstate" "github.com/XinFinOrg/XDPoSChain/XDCxlending/lendingstate"
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/rawdb" "github.com/XinFinOrg/XDPoSChain/core/rawdb"
"github.com/XinFinOrg/XDPoSChain/core/types"
) )
func Test_getCancelFeeV1(t *testing.T) { func Test_getCancelFeeV1(t *testing.T) {
@ -97,7 +98,7 @@ func Test_getCancelFee(t *testing.T) {
XDCx := XDCx.New(&XDCx.DefaultConfig) XDCx := XDCx.New(&XDCx.DefaultConfig)
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
stateCache := tradingstate.NewDatabase(db) stateCache := tradingstate.NewDatabase(db)
tradingStateDb, _ := tradingstate.New(common.Hash{}, stateCache) tradingStateDb, _ := tradingstate.New(types.EmptyRootHash, stateCache)
testTokenA := common.HexToAddress("0x1200000000000000000000000000000000000002") testTokenA := common.HexToAddress("0x1200000000000000000000000000000000000002")
testTokenB := common.HexToAddress("0x1300000000000000000000000000000000000003") testTokenB := common.HexToAddress("0x1300000000000000000000000000000000000003")

View file

@ -32,6 +32,7 @@ import (
"github.com/XinFinOrg/XDPoSChain/core" "github.com/XinFinOrg/XDPoSChain/core"
"github.com/XinFinOrg/XDPoSChain/core/rawdb" "github.com/XinFinOrg/XDPoSChain/core/rawdb"
"github.com/XinFinOrg/XDPoSChain/core/state" "github.com/XinFinOrg/XDPoSChain/core/state"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/core/vm" "github.com/XinFinOrg/XDPoSChain/core/vm"
"github.com/XinFinOrg/XDPoSChain/core/vm/runtime" "github.com/XinFinOrg/XDPoSChain/core/vm/runtime"
"github.com/XinFinOrg/XDPoSChain/internal/flags" "github.com/XinFinOrg/XDPoSChain/internal/flags"
@ -102,7 +103,7 @@ func runCmd(ctx *cli.Context) error {
chainConfig = gen.Config chainConfig = gen.Config
} else { } else {
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
statedb, _ = state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ = state.New(types.EmptyRootHash, state.NewDatabase(db))
} }
if ctx.String(SenderFlag.Name) != "" { if ctx.String(SenderFlag.Name) != "" {
sender = common.HexToAddress(ctx.String(SenderFlag.Name)) sender = common.HexToAddress(ctx.String(SenderFlag.Name))

View file

@ -185,7 +185,7 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
if db == nil { if db == nil {
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
} }
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
for addr, account := range g.Alloc { for addr, account := range g.Alloc {
statedb.AddBalance(addr, account.Balance) statedb.AddBalance(addr, account.Balance)
statedb.SetCode(addr, account.Code) statedb.SetCode(addr, account.Code)

View file

@ -71,7 +71,7 @@ func TestLookupStorage(t *testing.T) {
tx3 := types.NewTransaction(3, common.BytesToAddress([]byte{0x33}), big.NewInt(333), 3333, big.NewInt(33333), []byte{0x33, 0x33, 0x33}) tx3 := types.NewTransaction(3, common.BytesToAddress([]byte{0x33}), big.NewInt(333), 3333, big.NewInt(33333), []byte{0x33, 0x33, 0x33})
txs := []*types.Transaction{tx1, tx2, tx3} txs := []*types.Transaction{tx1, tx2, tx3}
block := types.NewBlock(&types.Header{Number: big.NewInt(314)}, txs, nil, nil) block := types.NewBlock(&types.Header{Root: types.EmptyRootHash, Number: big.NewInt(314)}, txs, nil, nil)
// Check that no transactions entries are in a pristine database // Check that no transactions entries are in a pristine database
for i, tx := range txs { for i, tx := range txs {

View file

@ -169,7 +169,7 @@ func (s *stateObject) getTrie(db Database) Trie {
var err error var err error
s.trie, err = db.OpenStorageTrie(s.addrHash, s.data.Root) s.trie, err = db.OpenStorageTrie(s.addrHash, s.data.Root)
if err != nil { if err != nil {
s.trie, _ = db.OpenStorageTrie(s.addrHash, common.Hash{}) s.trie, _ = db.OpenStorageTrie(s.addrHash, types.EmptyRootHash)
s.setError(fmt.Errorf("can't create storage trie: %v", err)) s.setError(fmt.Errorf("can't create storage trie: %v", err))
} }
} }

View file

@ -23,6 +23,7 @@ import (
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/rawdb" "github.com/XinFinOrg/XDPoSChain/core/rawdb"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/crypto" "github.com/XinFinOrg/XDPoSChain/crypto"
"github.com/XinFinOrg/XDPoSChain/ethdb" "github.com/XinFinOrg/XDPoSChain/ethdb"
checker "gopkg.in/check.v1" checker "gopkg.in/check.v1"
@ -89,7 +90,7 @@ func (s *StateSuite) TestDump(c *checker.C) {
func (s *StateSuite) SetUpTest(c *checker.C) { func (s *StateSuite) SetUpTest(c *checker.C) {
s.db = rawdb.NewMemoryDatabase() s.db = rawdb.NewMemoryDatabase()
s.state, _ = New(common.Hash{}, NewDatabase(s.db)) s.state, _ = New(types.EmptyRootHash, NewDatabase(s.db))
} }
func (s *StateSuite) TestNull(c *checker.C) { func (s *StateSuite) TestNull(c *checker.C) {
@ -135,7 +136,7 @@ func (s *StateSuite) TestSnapshotEmpty(c *checker.C) {
// printing/logging in tests (-check.vv does not work) // printing/logging in tests (-check.vv does not work)
func TestSnapshot2(t *testing.T) { func TestSnapshot2(t *testing.T) {
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
state, _ := New(common.Hash{}, NewDatabase(db)) state, _ := New(types.EmptyRootHash, NewDatabase(db))
stateobjaddr0 := toAddr([]byte("so0")) stateobjaddr0 := toAddr([]byte("so0"))
stateobjaddr1 := toAddr([]byte("so1")) stateobjaddr1 := toAddr([]byte("so1"))

View file

@ -39,7 +39,7 @@ import (
func TestUpdateLeaks(t *testing.T) { func TestUpdateLeaks(t *testing.T) {
// Create an empty state database // Create an empty state database
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
state, _ := New(common.Hash{}, NewDatabase(db)) state, _ := New(types.EmptyRootHash, NewDatabase(db))
// Update it with some accounts // Update it with some accounts
for i := byte(0); i < 255; i++ { for i := byte(0); i < 255; i++ {
@ -69,8 +69,8 @@ func TestIntermediateLeaks(t *testing.T) {
// Create two state databases, one transitioning to the final state, the other final from the beginning // Create two state databases, one transitioning to the final state, the other final from the beginning
transDb := rawdb.NewMemoryDatabase() transDb := rawdb.NewMemoryDatabase()
finalDb := rawdb.NewMemoryDatabase() finalDb := rawdb.NewMemoryDatabase()
transState, _ := New(common.Hash{}, NewDatabase(transDb)) transState, _ := New(types.EmptyRootHash, NewDatabase(transDb))
finalState, _ := New(common.Hash{}, NewDatabase(finalDb)) finalState, _ := New(types.EmptyRootHash, NewDatabase(finalDb))
modify := func(state *StateDB, addr common.Address, i, tweak byte) { modify := func(state *StateDB, addr common.Address, i, tweak byte) {
state.SetBalance(addr, big.NewInt(int64(11*i)+int64(tweak))) state.SetBalance(addr, big.NewInt(int64(11*i)+int64(tweak)))
@ -128,7 +128,7 @@ func TestIntermediateLeaks(t *testing.T) {
func TestCopy(t *testing.T) { func TestCopy(t *testing.T) {
// Create a random state test to copy and modify "independently" // Create a random state test to copy and modify "independently"
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
orig, _ := New(common.Hash{}, NewDatabase(db)) orig, _ := New(types.EmptyRootHash, NewDatabase(db))
for i := byte(0); i < 255; i++ { for i := byte(0); i < 255; i++ {
obj := orig.GetOrNewStateObject(common.BytesToAddress([]byte{i})) obj := orig.GetOrNewStateObject(common.BytesToAddress([]byte{i}))
@ -364,7 +364,7 @@ func (test *snapshotTest) run() bool {
// Run all actions and create snapshots. // Run all actions and create snapshots.
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
state, _ = New(common.Hash{}, NewDatabase(db)) state, _ = New(types.EmptyRootHash, NewDatabase(db))
snapshotRevs = make([]int, len(test.snapshots)) snapshotRevs = make([]int, len(test.snapshots))
sindex = 0 sindex = 0
) )
@ -378,7 +378,7 @@ func (test *snapshotTest) run() bool {
// Revert all snapshots in reverse order. Each revert must yield a state // Revert all snapshots in reverse order. Each revert must yield a state
// that is equivalent to fresh state with all actions up the snapshot applied. // that is equivalent to fresh state with all actions up the snapshot applied.
for sindex--; sindex >= 0; sindex-- { for sindex--; sindex >= 0; sindex-- {
checkstate, _ := New(common.Hash{}, state.Database()) checkstate, _ := New(types.EmptyRootHash, state.Database())
for _, action := range test.actions[:test.snapshots[sindex]] { for _, action := range test.actions[:test.snapshots[sindex]] {
action.fn(action, checkstate) action.fn(action, checkstate)
} }
@ -462,7 +462,7 @@ func TestStateDBAccessList(t *testing.T) {
memDb := rawdb.NewMemoryDatabase() memDb := rawdb.NewMemoryDatabase()
db := NewDatabase(memDb) db := NewDatabase(memDb)
state, _ := New(common.Hash{}, db) state, _ := New(types.EmptyRootHash, db)
state.accessList = newAccessList() state.accessList = newAccessList()
verifyAddrs := func(astrings ...string) { verifyAddrs := func(astrings ...string) {
@ -628,7 +628,7 @@ func TestStateDBAccessList(t *testing.T) {
func TestStateDBTransientStorage(t *testing.T) { func TestStateDBTransientStorage(t *testing.T) {
memDb := rawdb.NewMemoryDatabase() memDb := rawdb.NewMemoryDatabase()
db := NewDatabase(memDb) db := NewDatabase(memDb)
state, _ := New(common.Hash{}, db) state, _ := New(types.EmptyRootHash, db)
key := common.Hash{0x01} key := common.Hash{0x01}
value := common.Hash{0x02} value := common.Hash{0x02}

View file

@ -42,7 +42,7 @@ type testAccount struct {
func makeTestState() (Database, common.Hash, []*testAccount) { func makeTestState() (Database, common.Hash, []*testAccount) {
// Create an empty state // Create an empty state
db := NewDatabase(rawdb.NewMemoryDatabase()) db := NewDatabase(rawdb.NewMemoryDatabase())
state, _ := New(common.Hash{}, db) state, _ := New(types.EmptyRootHash, db)
// Fill it with some arbitrary data // Fill it with some arbitrary data
accounts := []*testAccount{} accounts := []*testAccount{}

View file

@ -80,6 +80,7 @@ func (bc *testBlockChain) Config() *params.ChainConfig {
func (bc *testBlockChain) CurrentBlock() *types.Block { func (bc *testBlockChain) CurrentBlock() *types.Block {
return types.NewBlock(&types.Header{ return types.NewBlock(&types.Header{
Root: types.EmptyRootHash,
GasLimit: atomic.LoadUint64(&bc.gasLimit), GasLimit: atomic.LoadUint64(&bc.gasLimit),
}, nil, nil, nil) }, nil, nil, nil)
} }
@ -134,7 +135,7 @@ func setupPool() (*TxPool, *ecdsa.PrivateKey) {
func setupPoolWithConfig(config *params.ChainConfig) (*TxPool, *ecdsa.PrivateKey) { func setupPoolWithConfig(config *params.ChainConfig) (*TxPool, *ecdsa.PrivateKey) {
diskdb := rawdb.NewMemoryDatabase() diskdb := rawdb.NewMemoryDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(diskdb)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(diskdb))
blockchain := &testBlockChain{statedb, 10000000, new(event.Feed)} blockchain := &testBlockChain{statedb, 10000000, new(event.Feed)}
key, _ := crypto.GenerateKey() key, _ := crypto.GenerateKey()
@ -224,7 +225,7 @@ func (c *testChain) State() (*state.StateDB, error) {
stdb := c.statedb stdb := c.statedb
if *c.trigger { if *c.trigger {
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
c.statedb, _ = state.New(common.Hash{}, state.NewDatabase(db)) c.statedb, _ = state.New(types.EmptyRootHash, state.NewDatabase(db))
// simulate that the new head block included tx0 and tx1 // simulate that the new head block included tx0 and tx1
c.statedb.SetNonce(c.address, 2) c.statedb.SetNonce(c.address, 2)
c.statedb.SetBalance(c.address, new(big.Int).SetUint64(params.Ether)) c.statedb.SetBalance(c.address, new(big.Int).SetUint64(params.Ether))
@ -243,7 +244,7 @@ func TestStateChangeDuringReset(t *testing.T) {
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
key, _ = crypto.GenerateKey() key, _ = crypto.GenerateKey()
address = crypto.PubkeyToAddress(key.PublicKey) address = crypto.PubkeyToAddress(key.PublicKey)
statedb, _ = state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ = state.New(types.EmptyRootHash, state.NewDatabase(db))
trigger = false trigger = false
) )
@ -442,7 +443,7 @@ func TestChainFork(t *testing.T) {
addr := crypto.PubkeyToAddress(key.PublicKey) addr := crypto.PubkeyToAddress(key.PublicKey)
resetState := func() { resetState := func() {
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
statedb.AddBalance(addr, big.NewInt(100000000000000)) statedb.AddBalance(addr, big.NewInt(100000000000000))
pool.chain = &testBlockChain{statedb, 1000000, new(event.Feed)} pool.chain = &testBlockChain{statedb, 1000000, new(event.Feed)}
@ -472,7 +473,7 @@ func TestDoubleNonce(t *testing.T) {
addr := crypto.PubkeyToAddress(key.PublicKey) addr := crypto.PubkeyToAddress(key.PublicKey)
resetState := func() { resetState := func() {
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
statedb.AddBalance(addr, big.NewInt(100000000000000)) statedb.AddBalance(addr, big.NewInt(100000000000000))
pool.chain = &testBlockChain{statedb, 1000000, new(event.Feed)} pool.chain = &testBlockChain{statedb, 1000000, new(event.Feed)}
@ -673,7 +674,7 @@ func TestPostponing(t *testing.T) {
// Create the pool to test the postponing with // Create the pool to test the postponing with
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain) pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
@ -887,7 +888,7 @@ func testQueueGlobalLimiting(t *testing.T, nolocals bool) {
// Create the pool to test the limit enforcement with // Create the pool to test the limit enforcement with
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig config := testTxPoolConfig
@ -980,7 +981,7 @@ func testQueueTimeLimiting(t *testing.T, nolocals bool) {
// Create the pool to test the non-expiration enforcement // Create the pool to test the non-expiration enforcement
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig config := testTxPoolConfig
@ -1166,7 +1167,7 @@ func TestPendingGlobalLimiting(t *testing.T) {
// Create the pool to test the limit enforcement with // Create the pool to test the limit enforcement with
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig config := testTxPoolConfig
@ -1269,7 +1270,7 @@ func TestCapClearsFromAll(t *testing.T) {
// Create the pool to test the limit enforcement with // Create the pool to test the limit enforcement with
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig config := testTxPoolConfig
@ -1304,7 +1305,7 @@ func TestPendingMinimumAllowance(t *testing.T) {
// Create the pool to test the limit enforcement with // Create the pool to test the limit enforcement with
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig config := testTxPoolConfig
@ -1353,7 +1354,7 @@ func TestRepricing(t *testing.T) {
// Create the pool to test the pricing enforcement with // Create the pool to test the pricing enforcement with
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain) pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
@ -1602,7 +1603,7 @@ func TestRepricingKeepsLocals(t *testing.T) {
// Create the pool to test the pricing enforcement with // Create the pool to test the pricing enforcement with
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
pool := NewTxPool(testTxPoolConfig, eip1559Config, blockchain) pool := NewTxPool(testTxPoolConfig, eip1559Config, blockchain)
@ -1677,7 +1678,7 @@ func TestPoolUnderpricing(t *testing.T) {
// Create the pool to test the pricing enforcement with // Create the pool to test the pricing enforcement with
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig config := testTxPoolConfig
@ -1784,7 +1785,7 @@ func TestPoolStableUnderpricing(t *testing.T) {
// Create the pool to test the pricing enforcement with // Create the pool to test the pricing enforcement with
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig config := testTxPoolConfig
@ -2017,7 +2018,7 @@ func TestDeduplication(t *testing.T) {
t.Parallel() t.Parallel()
// Create the pool to test the pricing enforcement with // Create the pool to test the pricing enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase())) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain) pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
@ -2084,7 +2085,7 @@ func TestReplacement(t *testing.T) {
// Create the pool to test the pricing enforcement with // Create the pool to test the pricing enforcement with
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain) pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
@ -2290,7 +2291,7 @@ func testTransactionJournaling(t *testing.T, nolocals bool) {
// Create the original pool to inject transaction into the journal // Create the original pool to inject transaction into the journal
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig config := testTxPoolConfig
@ -2389,7 +2390,7 @@ func TestStatusCheck(t *testing.T) {
// Create the pool to test the status retrievals with // Create the pool to test the status retrievals with
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain) pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)

View file

@ -24,6 +24,7 @@ import (
"testing" "testing"
"github.com/XinFinOrg/XDPoSChain/core/rawdb" "github.com/XinFinOrg/XDPoSChain/core/rawdb"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/common/hexutil" "github.com/XinFinOrg/XDPoSChain/common/hexutil"
@ -84,7 +85,7 @@ func TestEIP2200(t *testing.T) {
for i, tt := range eip2200Tests { for i, tt := range eip2200Tests {
address := common.BytesToAddress([]byte("contract")) address := common.BytesToAddress([]byte("contract"))
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
statedb.CreateAccount(address) statedb.CreateAccount(address)
statedb.SetCode(address, hexutil.MustDecode(tt.input)) statedb.SetCode(address, hexutil.MustDecode(tt.input))
statedb.SetState(address, common.Hash{}, common.BytesToHash([]byte{tt.original})) statedb.SetState(address, common.Hash{}, common.BytesToHash([]byte{tt.original}))
@ -135,7 +136,7 @@ func TestCreateGas(t *testing.T) {
var gasUsed = uint64(0) var gasUsed = uint64(0)
doCheck := func(testGas int) bool { doCheck := func(testGas int) bool {
address := common.BytesToAddress([]byte("contract")) address := common.BytesToAddress([]byte("contract"))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase())) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()))
statedb.CreateAccount(address) statedb.CreateAccount(address)
statedb.SetCode(address, hexutil.MustDecode(tt.code)) statedb.SetCode(address, hexutil.MustDecode(tt.code))
statedb.Finalise(true) statedb.Finalise(true)

View file

@ -30,6 +30,7 @@ import (
"github.com/XinFinOrg/XDPoSChain/common/math" "github.com/XinFinOrg/XDPoSChain/common/math"
"github.com/XinFinOrg/XDPoSChain/core/rawdb" "github.com/XinFinOrg/XDPoSChain/core/rawdb"
"github.com/XinFinOrg/XDPoSChain/core/state" "github.com/XinFinOrg/XDPoSChain/core/state"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/crypto" "github.com/XinFinOrg/XDPoSChain/crypto"
"github.com/XinFinOrg/XDPoSChain/params" "github.com/XinFinOrg/XDPoSChain/params"
"github.com/holiman/uint256" "github.com/holiman/uint256"
@ -588,7 +589,7 @@ func BenchmarkOpMstore(bench *testing.B) {
func TestOpTstore(t *testing.T) { func TestOpTstore(t *testing.T) {
var ( var (
statedb, _ = state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase())) statedb, _ = state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()))
env = NewEVM(BlockContext{}, TxContext{}, statedb, nil, params.TestChainConfig, Config{}) env = NewEVM(BlockContext{}, TxContext{}, statedb, nil, params.TestChainConfig, Config{})
stack = newstack() stack = newstack()
mem = NewMemory() mem = NewMemory()

View file

@ -24,6 +24,7 @@ import (
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/rawdb" "github.com/XinFinOrg/XDPoSChain/core/rawdb"
"github.com/XinFinOrg/XDPoSChain/core/state" "github.com/XinFinOrg/XDPoSChain/core/state"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/core/vm" "github.com/XinFinOrg/XDPoSChain/core/vm"
"github.com/XinFinOrg/XDPoSChain/crypto" "github.com/XinFinOrg/XDPoSChain/crypto"
"github.com/XinFinOrg/XDPoSChain/params" "github.com/XinFinOrg/XDPoSChain/params"
@ -113,7 +114,7 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
if cfg.State == nil { if cfg.State == nil {
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
cfg.State, _ = state.New(common.Hash{}, state.NewDatabase(db)) cfg.State, _ = state.New(types.EmptyRootHash, state.NewDatabase(db))
} }
var ( var (
address = common.BytesToAddress([]byte("contract")) address = common.BytesToAddress([]byte("contract"))
@ -149,7 +150,7 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) {
if cfg.State == nil { if cfg.State == nil {
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
cfg.State, _ = state.New(common.Hash{}, state.NewDatabase(db)) cfg.State, _ = state.New(types.EmptyRootHash, state.NewDatabase(db))
} }
var ( var (
vmenv = NewEnv(cfg) vmenv = NewEnv(cfg)

View file

@ -102,7 +102,7 @@ func TestExecute(t *testing.T) {
func TestCall(t *testing.T) { func TestCall(t *testing.T) {
db := rawdb.NewMemoryDatabase() db := rawdb.NewMemoryDatabase()
state, _ := state.New(common.Hash{}, state.NewDatabase(db)) state, _ := state.New(types.EmptyRootHash, state.NewDatabase(db))
address := common.HexToAddress("0x0a") address := common.HexToAddress("0x0a")
state.SetCode(address, []byte{ state.SetCode(address, []byte{
byte(vm.PUSH1), 10, byte(vm.PUSH1), 10,
@ -159,7 +159,7 @@ func BenchmarkCall(b *testing.B) {
func benchmarkEVM_Create(bench *testing.B, code string) { func benchmarkEVM_Create(bench *testing.B, code string) {
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
statedb, _ = state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ = state.New(types.EmptyRootHash, state.NewDatabase(db))
sender = common.BytesToAddress([]byte("sender")) sender = common.BytesToAddress([]byte("sender"))
receiver = common.BytesToAddress([]byte("receiver")) receiver = common.BytesToAddress([]byte("receiver"))
) )
@ -335,7 +335,7 @@ func TestBlockhash(t *testing.T) {
func benchmarkNonModifyingCode(gas uint64, code []byte, name string, b *testing.B) { func benchmarkNonModifyingCode(gas uint64, code []byte, name string, b *testing.B) {
cfg := new(Config) cfg := new(Config)
setDefaults(cfg) setDefaults(cfg)
cfg.State, _ = state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase())) cfg.State, _ = state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()))
cfg.GasLimit = gas cfg.GasLimit = gas
var ( var (
destination = common.BytesToAddress([]byte("contract")) destination = common.BytesToAddress([]byte("contract"))

View file

@ -21,6 +21,7 @@ import (
"testing" "testing"
"github.com/XinFinOrg/XDPoSChain/core/rawdb" "github.com/XinFinOrg/XDPoSChain/core/rawdb"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/state" "github.com/XinFinOrg/XDPoSChain/core/state"
@ -33,7 +34,7 @@ func TestStorageRangeAt(t *testing.T) {
// Create a state where account 0x010000... has a few storage entries. // Create a state where account 0x010000... has a few storage entries.
var ( var (
db = rawdb.NewMemoryDatabase() db = rawdb.NewMemoryDatabase()
state, _ = state.New(common.Hash{}, state.NewDatabase(db)) state, _ = state.New(types.EmptyRootHash, state.NewDatabase(db))
addr = common.Address{0x01} addr = common.Address{0x01}
keys = []common.Hash{ // hashes of Keys of storage keys = []common.Hash{ // hashes of Keys of storage
common.HexToHash("340dd630ad21bf010b4e676dbfa9ba9a02175262d1fa356232cfde6cb5b47ef2"), common.HexToHash("340dd630ad21bf010b4e676dbfa9ba9a02175262d1fa356232cfde6cb5b47ef2"),

View file

@ -39,7 +39,7 @@ var (
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
testAddress = crypto.PubkeyToAddress(testKey.PublicKey) testAddress = crypto.PubkeyToAddress(testKey.PublicKey)
genesis = core.GenesisBlockForTesting(testdb, testAddress, big.NewInt(1000000000)) genesis = core.GenesisBlockForTesting(testdb, testAddress, big.NewInt(1000000000))
unknownBlock = types.NewBlock(&types.Header{GasLimit: params.GenesisGasLimit}, nil, nil, nil) unknownBlock = types.NewBlock(&types.Header{Root: types.EmptyRootHash, GasLimit: params.GenesisGasLimit}, nil, nil, nil)
) )
// makeChain creates a chain of n blocks starting at and including parent. // makeChain creates a chain of n blocks starting at and including parent.

View file

@ -22,6 +22,7 @@ import (
"time" "time"
"github.com/XinFinOrg/XDPoSChain/core/rawdb" "github.com/XinFinOrg/XDPoSChain/core/rawdb"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/crypto" "github.com/XinFinOrg/XDPoSChain/crypto"
@ -79,7 +80,7 @@ func tfCodeAccess(db ethdb.Database, bhash common.Hash, num uint64) light.OdrReq
return nil return nil
} }
sti := light.StateTrieID(header) sti := light.StateTrieID(header)
ci := light.StorageTrieID(sti, crypto.Keccak256Hash(testContractAddr[:]), common.Hash{}) ci := light.StorageTrieID(sti, crypto.Keccak256Hash(testContractAddr[:]), types.EmptyRootHash)
return &light.CodeRequest{Id: ci, Hash: crypto.Keccak256Hash(testContractCodeDeployed)} return &light.CodeRequest{Id: ci, Hash: crypto.Keccak256Hash(testContractCodeDeployed)}
} }

View file

@ -147,7 +147,7 @@ func NewChtIndexer(db ethdb.Database, clientMode bool) *core.ChainIndexer {
// Reset implements core.ChainIndexerBackend // Reset implements core.ChainIndexerBackend
func (c *ChtIndexerBackend) Reset(section uint64, lastSectionHead common.Hash) error { func (c *ChtIndexerBackend) Reset(section uint64, lastSectionHead common.Hash) error {
var root common.Hash root := types.EmptyRootHash
if section > 0 { if section > 0 {
root = GetChtRoot(c.diskdb, section-1, lastSectionHead) root = GetChtRoot(c.diskdb, section-1, lastSectionHead)
} }
@ -245,7 +245,7 @@ func NewBloomTrieIndexer(db ethdb.Database, clientMode bool) *core.ChainIndexer
// Reset implements core.ChainIndexerBackend // Reset implements core.ChainIndexerBackend
func (b *BloomTrieIndexerBackend) Reset(section uint64, lastSectionHead common.Hash) error { func (b *BloomTrieIndexerBackend) Reset(section uint64, lastSectionHead common.Hash) error {
var root common.Hash root := types.EmptyRootHash
if section > 0 { if section > 0 {
root = GetBloomTrieRoot(b.diskdb, section-1, lastSectionHead) root = GetBloomTrieRoot(b.diskdb, section-1, lastSectionHead)
} }

View file

@ -187,7 +187,7 @@ func (t *StateTest) gasLimit(subtest StateSubtest) uint64 {
func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB { func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB {
sdb := state.NewDatabase(db) sdb := state.NewDatabase(db)
statedb, _ := state.New(common.Hash{}, sdb) statedb, _ := state.New(types.EmptyRootHash, sdb)
for addr, a := range accounts { for addr, a := range accounts {
statedb.SetCode(addr, a.Code) statedb.SetCode(addr, a.Code)
statedb.SetNonce(addr, a.Nonce) statedb.SetNonce(addr, a.Nonce)

View file

@ -295,7 +295,7 @@ func testIteratorContinueAfterError(t *testing.T, memonly bool) {
diskdb := memorydb.New() diskdb := memorydb.New()
triedb := NewDatabase(diskdb) triedb := NewDatabase(diskdb)
tr, _ := New(common.Hash{}, triedb) tr, _ := New(emptyRoot, triedb)
for _, val := range testdata1 { for _, val := range testdata1 {
tr.Update([]byte(val.k), []byte(val.v)) tr.Update([]byte(val.k), []byte(val.v))
} }
@ -386,7 +386,7 @@ func testIteratorContinueAfterSeekError(t *testing.T, memonly bool) {
diskdb := memorydb.New() diskdb := memorydb.New()
triedb := NewDatabase(diskdb) triedb := NewDatabase(diskdb)
ctr, _ := New(common.Hash{}, triedb) ctr, _ := New(emptyRoot, triedb)
for _, val := range testdata1 { for _, val := range testdata1 {
ctr.Update([]byte(val.k), []byte(val.v)) ctr.Update([]byte(val.k), []byte(val.v))
} }

View file

@ -419,7 +419,7 @@ func VerifyRangeProof(rootHash common.Hash, firstKey []byte, keys [][]byte, valu
// Special case, there is no edge proof at all. The given range is expected // Special case, there is no edge proof at all. The given range is expected
// to be the whole leaf-set in the trie. // to be the whole leaf-set in the trie.
if firstProof == nil && lastProof == nil { if firstProof == nil && lastProof == nil {
emptytrie, err := New(common.Hash{}, NewDatabase(memorydb.New())) emptytrie, err := New(emptyRoot, NewDatabase(memorydb.New()))
if err != nil { if err != nil {
return err, false return err, false
} }

View file

@ -28,7 +28,7 @@ import (
func makeTestTrie() (*Database, *Trie, map[string][]byte) { func makeTestTrie() (*Database, *Trie, map[string][]byte) {
// Create an empty trie // Create an empty trie
triedb := NewDatabase(memorydb.New()) triedb := NewDatabase(memorydb.New())
trie, _ := New(common.Hash{}, triedb) trie, _ := New(emptyRoot, triedb)
// Fill it with some arbitrary data // Fill it with some arbitrary data
content := make(map[string][]byte) content := make(map[string][]byte)
@ -90,7 +90,7 @@ func checkTrieConsistency(db *Database, root common.Hash) error {
func TestEmptySync(t *testing.T) { func TestEmptySync(t *testing.T) {
dbA := NewDatabase(memorydb.New()) dbA := NewDatabase(memorydb.New())
dbB := NewDatabase(memorydb.New()) dbB := NewDatabase(memorydb.New())
emptyA, _ := New(common.Hash{}, dbA) emptyA, _ := New(emptyRoot, dbA)
emptyB, _ := New(emptyRoot, dbB) emptyB, _ := New(emptyRoot, dbB)
for i, trie := range []*Trie{emptyA, emptyB} { for i, trie := range []*Trie{emptyA, emptyB} {

View file

@ -28,7 +28,9 @@ import (
) )
var ( var (
// TODO: remove file core/types/derive_sha.go, then remove emptyRoot and emptyState // TODO(daniel):
// 1. remove file core/types/derive_sha.go, Ref: #21502
// 2. then replace emptyRoot, emptyState with types.EmptyRootHash, types.EmptyCodeHash, Ref: #26718
// emptyRoot is the known root hash of an empty trie. // emptyRoot is the known root hash of an empty trie.
emptyRoot = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") emptyRoot = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")

View file

@ -44,7 +44,7 @@ func init() {
// Used for testing // Used for testing
func newEmpty() *Trie { func newEmpty() *Trie {
trie, _ := New(common.Hash{}, NewDatabase(memorydb.New())) trie, _ := New(emptyRoot, NewDatabase(memorydb.New()))
return trie return trie
} }
@ -84,7 +84,7 @@ func testMissingNode(t *testing.T, memonly bool) {
diskdb := memorydb.New() diskdb := memorydb.New()
triedb := NewDatabase(diskdb) triedb := NewDatabase(diskdb)
trie, _ := New(common.Hash{}, triedb) trie, _ := New(emptyRoot, triedb)
updateString(trie, "120000", "qwerqwerqwerqwerqwerqwerqwerqwer") updateString(trie, "120000", "qwerqwerqwerqwerqwerqwerqwerqwer")
updateString(trie, "123456", "asdfasdfasdfasdfasdfasdfasdfasdf") updateString(trie, "123456", "asdfasdfasdfasdfasdfasdfasdfasdf")
root, _ := trie.Commit(nil) root, _ := trie.Commit(nil)
@ -424,7 +424,7 @@ func runRandTestBool(rt randTest) bool {
func runRandTest(rt randTest) error { func runRandTest(rt randTest) error {
triedb := NewDatabase(memorydb.New()) triedb := NewDatabase(memorydb.New())
tr, _ := New(common.Hash{}, triedb) tr, _ := New(emptyRoot, triedb)
values := make(map[string]string) // tracks content of the trie values := make(map[string]string) // tracks content of the trie
for i, step := range rt { for i, step := range rt {
@ -460,7 +460,7 @@ func runRandTest(rt randTest) error {
} }
tr = newtr tr = newtr
case opItercheckhash: case opItercheckhash:
checktr, _ := New(common.Hash{}, triedb) checktr, _ := New(emptyRoot, triedb)
it := NewIterator(tr.NodeIterator(nil)) it := NewIterator(tr.NodeIterator(nil))
for it.Next() { for it.Next() {
checktr.Update(it.Key, it.Value) checktr.Update(it.Key, it.Value)
@ -497,7 +497,7 @@ func benchGet(b *testing.B, commit bool) {
trie := new(Trie) trie := new(Trie)
if commit { if commit {
tmpdb := tempDB(b) tmpdb := tempDB(b)
trie, _ = New(common.Hash{}, tmpdb) trie, _ = New(emptyRoot, tmpdb)
} }
k := make([]byte, 32) k := make([]byte, 32)
for i := 0; i < benchElemCount; i++ { for i := 0; i < benchElemCount; i++ {
@ -624,7 +624,7 @@ func TestTinyTrie(t *testing.T) {
t.Fatalf("3: got %x, exp %x", root, exp) t.Fatalf("3: got %x, exp %x", root, exp)
} }
checktr, _ := New(common.Hash{}, trie.Db) checktr, _ := New(emptyRoot, trie.Db)
it := NewIterator(trie.NodeIterator(nil)) it := NewIterator(trie.NodeIterator(nil))
for it.Next() { for it.Next() {
checktr.Update(it.Key, it.Value) checktr.Update(it.Key, it.Value)