mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-13 15:33:47 +00:00
try to use same statedb
This commit is contained in:
parent
9dd4e4b0f9
commit
2d0b9ea63d
4 changed files with 31 additions and 17 deletions
|
|
@ -665,7 +665,7 @@ func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state
|
||||||
// commit span
|
// commit span
|
||||||
headerNumber := header.Number.Uint64()
|
headerNumber := header.Number.Uint64()
|
||||||
fmt.Println(header.Number, headerNumber % c.config.Sprint)
|
fmt.Println(header.Number, headerNumber % c.config.Sprint)
|
||||||
if headerNumber > 0 &&
|
if /* headerNumber > 0 && */
|
||||||
headerNumber % c.config.Sprint == 0 {
|
headerNumber % c.config.Sprint == 0 {
|
||||||
cx := chainContext{Chain: chain, Bor: c}
|
cx := chainContext{Chain: chain, Bor: c}
|
||||||
fmt.Println("here 0.1")
|
fmt.Println("here 0.1")
|
||||||
|
|
@ -1002,6 +1002,7 @@ func (c *Bor) checkAndCommitSpan(
|
||||||
go func() {
|
go func() {
|
||||||
var err error
|
var err error
|
||||||
pending, err = c.isSpanPending(headerNumber - 1)
|
pending, err = c.isSpanPending(headerNumber - 1)
|
||||||
|
// pending, err = c.isSpanPending(headerNumber)
|
||||||
errors <- err
|
errors <- err
|
||||||
// wg.Done()
|
// wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
@ -1074,7 +1075,7 @@ func (c *Bor) fetchAndCommitSpan(
|
||||||
if err := json.Unmarshal(response.Result, &heimdallSpan); err != nil {
|
if err := json.Unmarshal(response.Result, &heimdallSpan); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println("here 4", heimdallSpan)
|
// fmt.Println("here 4", heimdallSpan)
|
||||||
// check if chain id matches with heimdall span
|
// check if chain id matches with heimdall span
|
||||||
if heimdallSpan.ChainID != c.chainConfig.ChainID.String() {
|
if heimdallSpan.ChainID != c.chainConfig.ChainID.String() {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import (
|
||||||
"github.com/maticnetwork/bor/consensus/bor"
|
"github.com/maticnetwork/bor/consensus/bor"
|
||||||
"github.com/maticnetwork/bor/core"
|
"github.com/maticnetwork/bor/core"
|
||||||
"github.com/maticnetwork/bor/core/rawdb"
|
"github.com/maticnetwork/bor/core/rawdb"
|
||||||
"github.com/maticnetwork/bor/core/state"
|
// "github.com/maticnetwork/bor/core/state"
|
||||||
"github.com/maticnetwork/bor/core/types"
|
"github.com/maticnetwork/bor/core/types"
|
||||||
// "github.com/maticnetwork/bor/core/vm"
|
// "github.com/maticnetwork/bor/core/vm"
|
||||||
"github.com/maticnetwork/bor/crypto"
|
"github.com/maticnetwork/bor/crypto"
|
||||||
|
|
@ -35,11 +35,11 @@ type initializeData struct {
|
||||||
|
|
||||||
func TestCommitSpan(t *testing.T) {
|
func TestCommitSpan(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
db = rawdb.NewMemoryDatabase()
|
// db = rawdb.NewMemoryDatabase()
|
||||||
// key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
// key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||||
// addr = crypto.PubkeyToAddress(key.PublicKey)
|
// addr = crypto.PubkeyToAddress(key.PublicKey)
|
||||||
)
|
)
|
||||||
init := buildEthereumInstance(t, db)
|
init := buildEthereumInstance(t, rawdb.NewMemoryDatabase())
|
||||||
chain := init.ethereum.BlockChain()
|
chain := init.ethereum.BlockChain()
|
||||||
engine := init.ethereum.Engine()
|
engine := init.ethereum.Engine()
|
||||||
_bor := engine.(*bor.Bor)
|
_bor := engine.(*bor.Bor)
|
||||||
|
|
@ -56,8 +56,10 @@ func TestCommitSpan(t *testing.T) {
|
||||||
h := &mocks.IHeimdallClient{}
|
h := &mocks.IHeimdallClient{}
|
||||||
h.On("FetchWithRetry", "bor", "span", "1").Return(res, nil)
|
h.On("FetchWithRetry", "bor", "span", "1").Return(res, nil)
|
||||||
_bor.SetHeimdallClient(h)
|
_bor.SetHeimdallClient(h)
|
||||||
|
db := init.ethereum.ChainDb()
|
||||||
block := init.genesis.ToBlock(db)
|
block := init.genesis.ToBlock(db)
|
||||||
statedb, _ := state.New(block.Root(), state.NewDatabase(db))
|
statedb, err := chain.StateAt(block.Root())
|
||||||
|
// statedb, _ := state.New(block.Root(), state.NewDatabase(db))
|
||||||
// _, _, _, err = chain.Processor().Process(block, statedb, vm.Config{})
|
// _, _, _, err = chain.Processor().Process(block, statedb, vm.Config{})
|
||||||
// fmt.Println(err)
|
// fmt.Println(err)
|
||||||
// _bor.Finalize(chain, block.Header(), statedb, nil, nil)
|
// _bor.Finalize(chain, block.Header(), statedb, nil, nil)
|
||||||
|
|
@ -69,9 +71,17 @@ func TestCommitSpan(t *testing.T) {
|
||||||
header := block.Header()
|
header := block.Header()
|
||||||
header.Number = big.NewInt(1)
|
header.Number = big.NewInt(1)
|
||||||
header.ParentHash = block.Hash()
|
header.ParentHash = block.Hash()
|
||||||
|
fmt.Println(block.Hash())
|
||||||
|
// header.Hash =
|
||||||
block = types.NewBlockWithHeader(header)
|
block = types.NewBlockWithHeader(header)
|
||||||
|
|
||||||
|
fmt.Println("statedb.IntermediateRoot", statedb.IntermediateRoot(true))
|
||||||
_bor.Finalize(chain, block.Header(), statedb, nil, nil)
|
_bor.Finalize(chain, block.Header(), statedb, nil, nil)
|
||||||
// _, _, _, err = chain.Processor().Process(block, statedb, vm.Config{})
|
// _, _, _, err = chain.Processor().Process(block, statedb, vm.Config{})
|
||||||
|
fmt.Println("statedb.IntermediateRoot 2", statedb.IntermediateRoot(true))
|
||||||
|
statedb, err = chain.StateAt(block.Root())
|
||||||
|
fmt.Println("statedb.IntermediateRoot 3", statedb.IntermediateRoot(true))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s", err)
|
t.Fatalf("%s", err)
|
||||||
}
|
}
|
||||||
|
|
@ -81,24 +91,24 @@ func TestCommitSpan(t *testing.T) {
|
||||||
// status, err := chain.writeBlockWithState(block, receipts, statedb)
|
// status, err := chain.writeBlockWithState(block, receipts, statedb)
|
||||||
|
|
||||||
// chain.chainmu.Lock()
|
// chain.chainmu.Lock()
|
||||||
k := big.NewInt(0)
|
td := big.NewInt(0)
|
||||||
k.Add(block.Difficulty(), chain.GetTdByHash(block.ParentHash()))
|
td.Add(block.Difficulty(), chain.GetTdByHash(block.ParentHash()))
|
||||||
fmt.Println("k", k)
|
fmt.Println("td", td)
|
||||||
|
|
||||||
rawdb.WriteTd(db,
|
rawdb.WriteTd(db,
|
||||||
block.Hash(),
|
block.Hash(),
|
||||||
block.NumberU64(),
|
block.NumberU64(),
|
||||||
k,
|
td,
|
||||||
)
|
)
|
||||||
rawdb.WriteBlock(db, block)
|
rawdb.WriteBlock(db, block)
|
||||||
root, err := statedb.Commit(true /* false ??*/)
|
root, err := statedb.Commit(false)
|
||||||
fmt.Println("root", root)
|
fmt.Println("root", root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s", err)
|
t.Fatalf("%s", err)
|
||||||
}
|
}
|
||||||
if err := statedb.Reset(root); err != nil {
|
// if err := statedb.Reset(root); err != nil {
|
||||||
t.Fatalf("state reset after block %d failed: %v", block.NumberU64(), err)
|
// t.Fatalf("state reset after block %d failed: %v", block.NumberU64(), err)
|
||||||
}
|
// }
|
||||||
// blockchain.chainmu.Unlock()
|
// blockchain.chainmu.Unlock()
|
||||||
|
|
||||||
assert.True(t, h.AssertNumberOfCalls(t, "FetchWithRetry", 1))
|
assert.True(t, h.AssertNumberOfCalls(t, "FetchWithRetry", 1))
|
||||||
|
|
@ -111,8 +121,8 @@ func TestCommitSpan(t *testing.T) {
|
||||||
validators, _ = _bor.GetCurrentValidators(0, 256)
|
validators, _ = _bor.GetCurrentValidators(0, 256)
|
||||||
fmt.Println(4, validators)
|
fmt.Println(4, validators)
|
||||||
|
|
||||||
// validators, _ = _bor.GetCurrentValidators(1, 256)
|
validators, _ = _bor.GetCurrentValidators(1, 256)
|
||||||
// fmt.Println(4, validators)
|
fmt.Println(4, validators)
|
||||||
// engine
|
// engine
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -193,7 +203,7 @@ func buildEthereumInstance(t *testing.T, db ethdb.Database) (*initializeData) {
|
||||||
|
|
||||||
var ethereum *eth.Ethereum
|
var ethereum *eth.Ethereum
|
||||||
stack.Service(ðereum)
|
stack.Service(ðereum)
|
||||||
|
ethConf.Genesis.MustCommit(ethereum.ChainDb())
|
||||||
return &initializeData{
|
return &initializeData{
|
||||||
genesis: gen,
|
genesis: gen,
|
||||||
ethereum: ethereum,
|
ethereum: ethereum,
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ package eth
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/maticnetwork/bor/accounts"
|
"github.com/maticnetwork/bor/accounts"
|
||||||
|
|
@ -101,6 +102,7 @@ func (b *EthAPIBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
if header == nil {
|
if header == nil {
|
||||||
|
fmt.Println("yoyo")
|
||||||
return nil, nil, errors.New("header not found")
|
return nil, nil, errors.New("header not found")
|
||||||
}
|
}
|
||||||
stateDb, err := b.eth.BlockChain().StateAt(header.Root)
|
stateDb, err := b.eth.BlockChain().StateAt(header.Root)
|
||||||
|
|
|
||||||
|
|
@ -730,6 +730,7 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNr rpc.BlockNumb
|
||||||
defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now())
|
defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now())
|
||||||
|
|
||||||
state, header, err := b.StateAndHeaderByNumber(ctx, blockNr)
|
state, header, err := b.StateAndHeaderByNumber(ctx, blockNr)
|
||||||
|
fmt.Println("statedb.IntermediateRoot in DoCall", state.IntermediateRoot(true))
|
||||||
if state == nil || err != nil {
|
if state == nil || err != nil {
|
||||||
return nil, 0, false, err
|
return nil, 0, false, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue