Hopefully an even faster version of mocked sentry (#8402)

This commit is contained in:
Giulio rebuffo 2023-10-07 22:30:10 +02:00 committed by GitHub
parent d4d5cb9561
commit d90572b786
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 12 deletions

View File

@ -152,11 +152,11 @@ test3:
## test-integration: run integration tests with a 30m timeout
test-integration:
@cd erigon-lib && $(MAKE) test
$(GOTEST) --timeout 120m -tags $(BUILD_TAGS),integration
$(GOTEST) --timeout 240m -tags $(BUILD_TAGS),integration
test3-integration:
@cd erigon-lib && $(MAKE) test
$(GOTEST) --timeout 120m -tags $(BUILD_TAGS),integration,e3
$(GOTEST) --timeout 240m -tags $(BUILD_TAGS),integration,e3
## lint-deps: install lint dependencies
lint-deps:

View File

@ -743,7 +743,7 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
checkStateRoot := true
pipelineStages := stages2.NewPipelineStages(ctx, chainKv, config, backend.sentriesClient, backend.notifications, backend.downloaderClient, blockReader, blockRetire, backend.agg, backend.silkworm, backend.forkValidator, logger, checkStateRoot)
backend.pipelineStagedSync = stagedsync.New(pipelineStages, stagedsync.PipelineUnwindOrder, stagedsync.PipelinePruneOrder, logger)
backend.eth1ExecutionServer = eth1.NewEthereumExecutionModule(blockReader, chainKv, backend.pipelineStagedSync, backend.forkValidator, chainConfig, assembleBlockPOS, hook, backend.notifications.Accumulator, backend.notifications.StateChangesConsumer, logger, config.HistoryV3)
backend.eth1ExecutionServer = eth1.NewEthereumExecutionModule(blockReader, chainKv, backend.pipelineStagedSync, backend.forkValidator, chainConfig, assembleBlockPOS, hook, backend.notifications.Accumulator, backend.notifications.StateChangesConsumer, logger, backend.engine, config.HistoryV3)
executionRpc := direct.NewExecutionClientDirect(backend.eth1ExecutionServer)
engineBackendRPC := engineapi.NewEngineServer(
ctx,

View File

@ -122,6 +122,7 @@ func (bt *BlockTest) Run(t *testing.T, checkStateRoot bool) error {
}
engine := ethconsensusconfig.CreateConsensusEngineBareBones(config, log.New())
m := mock.MockWithGenesisEngine(t, bt.genesis(config), engine, false, checkStateRoot)
defer m.Close()
bt.br = m.BlockReader
// import pre accounts & construct test genesis block & state root

View File

@ -14,6 +14,7 @@ import (
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/common/math"
"github.com/ledgerwatch/erigon/consensus"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/types"
@ -54,12 +55,14 @@ type EthereumExecutionModule struct {
// configuration
config *chain.Config
historyV3 bool
// consensus
engine consensus.Engine
execution.UnimplementedExecutionServer
}
func NewEthereumExecutionModule(blockReader services.FullBlockReader, db kv.RwDB, executionPipeline *stagedsync.Sync, forkValidator *engine_helpers.ForkValidator,
config *chain.Config, builderFunc builder.BlockBuilderFunc, hook *stages.Hook, accumulator *shards.Accumulator, stateChangeConsumer shards.StateChangeConsumer, logger log.Logger, historyV3 bool) *EthereumExecutionModule {
config *chain.Config, builderFunc builder.BlockBuilderFunc, hook *stages.Hook, accumulator *shards.Accumulator, stateChangeConsumer shards.StateChangeConsumer, logger log.Logger, engine consensus.Engine, historyV3 bool) *EthereumExecutionModule {
return &EthereumExecutionModule{
blockReader: blockReader,
db: db,
@ -73,6 +76,7 @@ func NewEthereumExecutionModule(blockReader services.FullBlockReader, db kv.RwDB
hook: hook,
accumulator: accumulator,
stateChangeConsumer: stateChangeConsumer,
engine: engine,
}
}

View File

@ -11,6 +11,7 @@ import (
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/rawdbv3"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/eth/stagedsync"
"github.com/ledgerwatch/erigon/eth/stagedsync/stages"
)
@ -246,6 +247,25 @@ func (e *EthereumExecutionModule) updateForkChoice(ctx context.Context, blockHas
}
// Mark all new canonicals as canonicals
for _, canonicalSegment := range newCanonicals {
chainReader := stagedsync.NewChainReaderImpl(e.config, tx, e.blockReader, e.logger)
b := rawdb.ReadBlock(tx, canonicalSegment.hash, canonicalSegment.number)
if b == nil {
sendForkchoiceErrorWithoutWaiting(outcomeCh, fmt.Errorf("unexpected chain cap: %d", canonicalSegment.number))
return
}
if err := e.engine.VerifyHeader(chainReader, b.Header(), true); err != nil {
sendForkchoiceErrorWithoutWaiting(outcomeCh, err)
return
}
if err := e.engine.VerifyUncles(chainReader, b.Header(), b.Uncles()); err != nil {
sendForkchoiceErrorWithoutWaiting(outcomeCh, err)
return
}
if err := rawdb.WriteCanonicalHash(tx, canonicalSegment.hash, canonicalSegment.number); err != nil {
sendForkchoiceErrorWithoutWaiting(outcomeCh, err)
return

View File

@ -464,7 +464,7 @@ func MockWithEverything(tb testing.TB, gspec *types.Genesis, key *ecdsa.PrivateK
snapshotsDownloader, mock.BlockReader, blockRetire, mock.agg, nil, forkValidator, logger, checkStateRoot)
mock.posStagedSync = stagedsync.New(pipelineStages, stagedsync.PipelineUnwindOrder, stagedsync.PipelinePruneOrder, logger)
mock.Eth1ExecutionService = eth1.NewEthereumExecutionModule(mock.BlockReader, mock.DB, mock.posStagedSync, forkValidator, mock.ChainConfig, assembleBlockPOS, nil, mock.Notifications.Accumulator, mock.Notifications.StateChangesConsumer, logger, histV3)
mock.Eth1ExecutionService = eth1.NewEthereumExecutionModule(mock.BlockReader, mock.DB, mock.posStagedSync, forkValidator, mock.ChainConfig, assembleBlockPOS, nil, mock.Notifications.Accumulator, mock.Notifications.StateChangesConsumer, logger, engine, histV3)
mock.sentriesClient.Hd.StartPoSDownloader(mock.Ctx, sendHeaderRequest, penalize)
@ -674,16 +674,20 @@ func (ms *MockSentry) insertPoSBlocks(chain *core.ChainPack) error {
if err := wr.InsertBlocksAndWait(chain.Blocks); err != nil {
return err
}
vRes, err := ms.Eth1ExecutionService.ValidateChain(ms.Ctx, &execution.ValidationRequest{
Hash: gointerfaces.ConvertHashToH256(chain.Blocks[chain.Length()-1].Hash()),
Number: chain.Blocks[chain.Length()-1].NumberU64(),
})
tipHash := chain.TopBlock.Hash()
status, lvh, err := wr.UpdateForkChoice(tipHash, tipHash, tipHash)
if err != nil {
return err
}
wr.UpdateForkChoice(gointerfaces.ConvertH256ToHash(vRes.LatestValidHash), gointerfaces.ConvertH256ToHash(vRes.LatestValidHash), gointerfaces.ConvertH256ToHash(vRes.LatestValidHash))
if vRes.ValidationStatus != execution.ExecutionStatus_Success {
return fmt.Errorf("insertion failed for block %d, code: %s", chain.Blocks[chain.Length()-1].NumberU64(), vRes.ValidationStatus.String())
ms.DB.Update(ms.Ctx, func(tx kv.RwTx) error {
rawdb.WriteHeadBlockHash(tx, lvh)
return nil
})
if status != execution.ExecutionStatus_Success {
return fmt.Errorf("insertion failed for block %d, code: %s", chain.Blocks[chain.Length()-1].NumberU64(), status.String())
}
return nil