mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
stagedsync: implement bor span for chain reader and fix loggers (#9146)
While working on fixing the bor mining loop I stumbled across an error in `ChainReader.BorSpan` - not implemented panic. Also hit a few other panics due to missed logger in `ChainReaderImpl` struct initialisations. This PR fixes both.
This commit is contained in:
parent
ebe16d8360
commit
98cc1ee808
@ -23,6 +23,8 @@ import (
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/chain"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/common/length"
|
||||
@ -35,7 +37,7 @@ import (
|
||||
"github.com/ledgerwatch/erigon/eth/stagedsync"
|
||||
"github.com/ledgerwatch/erigon/params"
|
||||
"github.com/ledgerwatch/erigon/turbo/stages/mock"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
"github.com/ledgerwatch/erigon/turbo/testlog"
|
||||
)
|
||||
|
||||
// testerAccountPool is a pool to maintain currently active tester accounts,
|
||||
@ -392,6 +394,7 @@ func TestClique(t *testing.T) {
|
||||
tt := tt
|
||||
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
logger := testlog.Logger(t, log.LvlInfo)
|
||||
// Create the account pool and generate the initial set of signers
|
||||
accounts := newTesterAccountPool()
|
||||
|
||||
@ -509,7 +512,13 @@ func TestClique(t *testing.T) {
|
||||
|
||||
var snap *clique.Snapshot
|
||||
if err := m.DB.View(context.Background(), func(tx kv.Tx) error {
|
||||
snap, err = engine.Snapshot(stagedsync.ChainReader{Cfg: config, Db: tx, BlockReader: m.BlockReader}, head.NumberU64(), head.Hash(), nil)
|
||||
chainReader := stagedsync.ChainReader{
|
||||
Cfg: config,
|
||||
Db: tx,
|
||||
BlockReader: m.BlockReader,
|
||||
Logger: logger,
|
||||
}
|
||||
snap, err = engine.Snapshot(chainReader, head.NumberU64(), head.Hash(), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -20,13 +20,17 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
"github.com/ledgerwatch/erigon/consensus"
|
||||
"github.com/ledgerwatch/erigon/consensus/ethash"
|
||||
"github.com/ledgerwatch/erigon/core"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
"github.com/ledgerwatch/erigon/eth/stagedsync"
|
||||
"github.com/ledgerwatch/erigon/params"
|
||||
"github.com/ledgerwatch/erigon/turbo/stages/mock"
|
||||
"github.com/ledgerwatch/erigon/turbo/testlog"
|
||||
)
|
||||
|
||||
// Tests that simple header verification works, for both good and bad blocks.
|
||||
@ -37,6 +41,7 @@ func TestHeaderVerification(t *testing.T) {
|
||||
gspec = &types.Genesis{Config: params.TestChainConfig}
|
||||
engine = ethash.NewFaker()
|
||||
)
|
||||
logger := testlog.Logger(t, log.LvlInfo)
|
||||
checkStateRoot := true
|
||||
m := mock.MockWithGenesisEngine(t, gspec, engine, false, checkStateRoot)
|
||||
|
||||
@ -48,13 +53,19 @@ func TestHeaderVerification(t *testing.T) {
|
||||
for i := 0; i < chain.Length(); i++ {
|
||||
if err := m.DB.View(context.Background(), func(tx kv.Tx) error {
|
||||
for j, valid := range []bool{true, false} {
|
||||
if valid {
|
||||
engine := ethash.NewFaker()
|
||||
err = engine.VerifyHeader(stagedsync.ChainReader{Cfg: *params.TestChainConfig, Db: tx, BlockReader: m.BlockReader}, chain.Headers[i], true)
|
||||
} else {
|
||||
engine := ethash.NewFakeFailer(chain.Headers[i].Number.Uint64())
|
||||
err = engine.VerifyHeader(stagedsync.ChainReader{Cfg: *params.TestChainConfig, Db: tx, BlockReader: m.BlockReader}, chain.Headers[i], true)
|
||||
chainReader := stagedsync.ChainReader{
|
||||
Cfg: *params.TestChainConfig,
|
||||
Db: tx,
|
||||
BlockReader: m.BlockReader,
|
||||
Logger: logger,
|
||||
}
|
||||
var engine consensus.Engine
|
||||
if valid {
|
||||
engine = ethash.NewFaker()
|
||||
} else {
|
||||
engine = ethash.NewFakeFailer(chain.Headers[i].Number.Uint64())
|
||||
}
|
||||
err = engine.VerifyHeader(chainReader, chain.Headers[i], true)
|
||||
if (err == nil) != valid {
|
||||
t.Errorf("test %d.%d: validity mismatch: have %v, want %v", i, j, err, valid)
|
||||
}
|
||||
@ -79,6 +90,7 @@ func TestHeaderWithSealVerification(t *testing.T) {
|
||||
gspec = &types.Genesis{Config: params.TestChainAuraConfig}
|
||||
engine = ethash.NewFaker()
|
||||
)
|
||||
logger := testlog.Logger(t, log.LvlInfo)
|
||||
checkStateRoot := true
|
||||
m := mock.MockWithGenesisEngine(t, gspec, engine, false, checkStateRoot)
|
||||
|
||||
@ -91,13 +103,19 @@ func TestHeaderWithSealVerification(t *testing.T) {
|
||||
for i := 0; i < chain.Length(); i++ {
|
||||
if err := m.DB.View(context.Background(), func(tx kv.Tx) error {
|
||||
for j, valid := range []bool{true, false} {
|
||||
if valid {
|
||||
engine := ethash.NewFaker()
|
||||
err = engine.VerifyHeader(stagedsync.ChainReader{Cfg: *params.TestChainAuraConfig, Db: tx, BlockReader: m.BlockReader}, chain.Headers[i], true)
|
||||
} else {
|
||||
engine := ethash.NewFakeFailer(chain.Headers[i].Number.Uint64())
|
||||
err = engine.VerifyHeader(stagedsync.ChainReader{Cfg: *params.TestChainAuraConfig, Db: tx, BlockReader: m.BlockReader}, chain.Headers[i], true)
|
||||
chainReader := stagedsync.ChainReader{
|
||||
Cfg: *params.TestChainAuraConfig,
|
||||
Db: tx,
|
||||
BlockReader: m.BlockReader,
|
||||
Logger: logger,
|
||||
}
|
||||
var engine consensus.Engine
|
||||
if valid {
|
||||
engine = ethash.NewFaker()
|
||||
} else {
|
||||
engine = ethash.NewFakeFailer(chain.Headers[i].Number.Uint64())
|
||||
}
|
||||
err = engine.VerifyHeader(chainReader, chain.Headers[i], true)
|
||||
if (err == nil) != valid {
|
||||
t.Errorf("test %d.%d: validity mismatch: have %v, want %v", i, j, err, valid)
|
||||
}
|
||||
|
@ -4,23 +4,24 @@ import (
|
||||
"context"
|
||||
"math/big"
|
||||
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/chain"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
"github.com/ledgerwatch/erigon/rlp"
|
||||
"github.com/ledgerwatch/erigon/turbo/services"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
|
||||
"github.com/ledgerwatch/erigon/core/rawdb"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
"github.com/ledgerwatch/erigon/rlp"
|
||||
"github.com/ledgerwatch/erigon/turbo/services"
|
||||
)
|
||||
|
||||
// Implements consensus.ChainReader
|
||||
// ChainReader implements consensus.ChainReader
|
||||
type ChainReader struct {
|
||||
Cfg chain.Config
|
||||
|
||||
Db kv.Getter
|
||||
BlockReader services.FullBlockReader
|
||||
Logger log.Logger
|
||||
}
|
||||
|
||||
// Config retrieves the blockchain's chain configuration.
|
||||
@ -81,10 +82,16 @@ func (cr ChainReader) FrozenBlocks() uint64 {
|
||||
return cr.BlockReader.FrozenBlocks()
|
||||
}
|
||||
|
||||
func (cr ChainReader) BorEventsByBlock(hash libcommon.Hash, number uint64) []rlp.RawValue {
|
||||
panic("")
|
||||
func (cr ChainReader) BorEventsByBlock(_ libcommon.Hash, _ uint64) []rlp.RawValue {
|
||||
panic("bor events by block not implemented")
|
||||
}
|
||||
|
||||
func (cr ChainReader) BorSpan(spanId uint64) []byte {
|
||||
panic("")
|
||||
span, err := cr.BlockReader.Span(context.Background(), cr.Db, spanId)
|
||||
if err != nil {
|
||||
cr.Logger.Error("BorSpan failed", "err", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
return span
|
||||
}
|
||||
|
@ -6,14 +6,14 @@ import (
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/chain"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/common/dbg"
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
"github.com/ledgerwatch/erigon/core/rawdb"
|
||||
"github.com/ledgerwatch/erigon/core/rawdb/blockio"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
|
||||
"github.com/ledgerwatch/erigon/dataflow"
|
||||
"github.com/ledgerwatch/erigon/eth/stagedsync/stages"
|
||||
"github.com/ledgerwatch/erigon/turbo/adapter"
|
||||
@ -134,7 +134,7 @@ func BodiesForward(
|
||||
prevProgress := bodyProgress
|
||||
var noProgressCount uint = 0 // How many time the progress was printed without actual progress
|
||||
var totalDelivered uint64 = 0
|
||||
cr := ChainReader{Cfg: cfg.chanConfig, Db: tx, BlockReader: cfg.blockReader}
|
||||
cr := ChainReader{Cfg: cfg.chanConfig, Db: tx, BlockReader: cfg.blockReader, Logger: logger}
|
||||
|
||||
loopBody := func() (bool, error) {
|
||||
// loopCount is used here to ensure we don't get caught in a constant loop of making requests
|
||||
|
@ -9,19 +9,19 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/c2h5oh/datasize"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/chain"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/common/dbg"
|
||||
"github.com/ledgerwatch/erigon-lib/common/hexutility"
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
"github.com/ledgerwatch/erigon/core/rawdb/blockio"
|
||||
"github.com/ledgerwatch/erigon/eth/ethconfig"
|
||||
"github.com/ledgerwatch/erigon/eth/stagedsync/stages"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
"github.com/ledgerwatch/erigon/core/rawdb"
|
||||
"github.com/ledgerwatch/erigon/core/rawdb/blockio"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
"github.com/ledgerwatch/erigon/eth/ethconfig"
|
||||
"github.com/ledgerwatch/erigon/eth/stagedsync/stages"
|
||||
"github.com/ledgerwatch/erigon/rlp"
|
||||
"github.com/ledgerwatch/erigon/turbo/engineapi/engine_helpers"
|
||||
"github.com/ledgerwatch/erigon/turbo/services"
|
||||
@ -183,7 +183,12 @@ func HeadersPOW(
|
||||
}
|
||||
TEMP TESTING */
|
||||
headerInserter := headerdownload.NewHeaderInserter(logPrefix, localTd, startProgress, cfg.blockReader)
|
||||
cfg.hd.SetHeaderReader(&ChainReaderImpl{config: &cfg.chainConfig, tx: tx, blockReader: cfg.blockReader})
|
||||
cfg.hd.SetHeaderReader(&ChainReaderImpl{
|
||||
config: &cfg.chainConfig,
|
||||
tx: tx,
|
||||
blockReader: cfg.blockReader,
|
||||
logger: logger,
|
||||
})
|
||||
|
||||
stopped := false
|
||||
var noProgressCounter uint = 0
|
||||
|
@ -8,11 +8,10 @@ import (
|
||||
"time"
|
||||
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
"github.com/ledgerwatch/erigon-lib/chain"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon/turbo/services"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/chain"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
"github.com/ledgerwatch/erigon/common/debug"
|
||||
"github.com/ledgerwatch/erigon/consensus"
|
||||
@ -22,6 +21,7 @@ import (
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
"github.com/ledgerwatch/erigon/eth/ethutils"
|
||||
"github.com/ledgerwatch/erigon/params"
|
||||
"github.com/ledgerwatch/erigon/turbo/services"
|
||||
)
|
||||
|
||||
type MiningBlock struct {
|
||||
@ -127,7 +127,7 @@ func SpawnMiningCreateBlockStage(s *StageState, tx kv.RwTx, cfg MiningCreateBloc
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
chain := ChainReader{Cfg: cfg.chainConfig, Db: tx, BlockReader: cfg.blockReader}
|
||||
chain := ChainReader{Cfg: cfg.chainConfig, Db: tx, BlockReader: cfg.blockReader, Logger: logger}
|
||||
var GetBlocksFromHash = func(hash libcommon.Hash, n int) (blocks []*types.Block) {
|
||||
number := rawdb.ReadHeaderNumber(tx, hash)
|
||||
if number == nil {
|
||||
|
@ -10,15 +10,14 @@ import (
|
||||
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
"github.com/holiman/uint256"
|
||||
"github.com/ledgerwatch/erigon-lib/kv/membatch"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/chain"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
"github.com/ledgerwatch/erigon-lib/kv/membatch"
|
||||
types2 "github.com/ledgerwatch/erigon-lib/types"
|
||||
|
||||
"github.com/ledgerwatch/erigon/consensus"
|
||||
"github.com/ledgerwatch/erigon/core"
|
||||
"github.com/ledgerwatch/erigon/core/rawdb"
|
||||
@ -89,7 +88,7 @@ func SpawnMiningExecStage(s *StageState, tx kv.RwTx, cfg MiningExecCfg, quit <-c
|
||||
ibs := state.New(stateReader)
|
||||
stateWriter := state.NewPlainStateWriter(tx, tx, current.Header.Number.Uint64())
|
||||
|
||||
chainReader := ChainReader{Cfg: cfg.chainConfig, Db: tx, BlockReader: cfg.blockReader}
|
||||
chainReader := ChainReader{Cfg: cfg.chainConfig, Db: tx, BlockReader: cfg.blockReader, Logger: logger}
|
||||
core.InitializeBlockExecution(cfg.engine, chainReader, current.Header, &cfg.chainConfig, ibs, logger)
|
||||
|
||||
// Create an empty block based on temporary copied state for
|
||||
@ -163,7 +162,7 @@ func SpawnMiningExecStage(s *StageState, tx kv.RwTx, cfg MiningExecCfg, quit <-c
|
||||
}
|
||||
|
||||
var err error
|
||||
_, current.Txs, current.Receipts, err = core.FinalizeBlockExecution(cfg.engine, stateReader, current.Header, current.Txs, current.Uncles, stateWriter, &cfg.chainConfig, ibs, current.Receipts, current.Withdrawals, ChainReaderImpl{config: &cfg.chainConfig, tx: tx, blockReader: cfg.blockReader}, true, logger)
|
||||
_, current.Txs, current.Receipts, err = core.FinalizeBlockExecution(cfg.engine, stateReader, current.Header, current.Txs, current.Uncles, stateWriter, &cfg.chainConfig, ibs, current.Receipts, current.Withdrawals, ChainReaderImpl{config: &cfg.chainConfig, tx: tx, blockReader: cfg.blockReader, logger: logger}, true, logger)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -3,14 +3,14 @@ package stagedsync
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/chain"
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
"github.com/ledgerwatch/erigon/turbo/builder"
|
||||
"github.com/ledgerwatch/erigon/turbo/services"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/chain"
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
"github.com/ledgerwatch/erigon/consensus"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
"github.com/ledgerwatch/erigon/turbo/builder"
|
||||
"github.com/ledgerwatch/erigon/turbo/services"
|
||||
)
|
||||
|
||||
type MiningFinishCfg struct {
|
||||
@ -95,7 +95,7 @@ func SpawnMiningFinishStage(s *StageState, tx kv.RwTx, cfg MiningFinishCfg, quit
|
||||
default:
|
||||
logger.Trace("No in-flight sealing task.")
|
||||
}
|
||||
chain := ChainReader{Cfg: cfg.chainConfig, Db: tx, BlockReader: cfg.blockReader}
|
||||
chain := ChainReader{Cfg: cfg.chainConfig, Db: tx, BlockReader: cfg.blockReader, Logger: logger}
|
||||
if err := cfg.engine.Seal(chain, block, cfg.miningState.MiningResultCh, cfg.sealCancel); err != nil {
|
||||
logger.Warn("Block sealing failed", "err", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user