public Task <Block> SealBlock(Block block, CancellationToken cancellationToken) { if (_poSSwitcher.IsPostMerge(block.Header)) { return(Task.FromResult(block)); } return(_preMergeSealValidator.SealBlock(block, cancellationToken)); }
public BlockReward[] CalculateRewards(Block block) { if (_poSSwitcher.IsPostMerge(block.Header)) { return(NoBlockRewards.Instance.CalculateRewards(block)); } return(_beforeTheMerge.CalculateRewards(block)); }
public bool Validate(BlockHeader header, BlockHeader[] uncles) { if (_poSSwitcher.IsPostMerge(header)) { return(true); } return(_preMergeUnclesValidator.Validate(header, uncles)); }
public void RecoverData(Block block) { if (block.TotalDifficulty is not null) { block.Header.IsPostMerge = _poSSwitcher.IsPostMerge(block.Header); } if (block.Author is null && block.IsPostMerge) { block.Header.Author = block.Beneficiary; } }
public void givenAnInvalidBlock_ifParentIsNotPostMerge_thenLastValidHashShouldBeZero() { IBlockFinder blockFinder = Substitute.For <IBlockFinder>(); IBlockCacheService blockCacheService = new BlockCacheService(); Keccak invalidBlock = Keccak.Compute("A"); BlockHeader parentBlockHeader = new BlockHeaderBuilder().TestObject; blockCacheService.BlockCache[parentBlockHeader.Hash] = new Block(parentBlockHeader); IPoSSwitcher poSSwitcher = Substitute.For <IPoSSwitcher>(); poSSwitcher.IsPostMerge(parentBlockHeader).Returns(false); _tracker = new(poSSwitcher, blockFinder, blockCacheService, new TestLogManager()); // Small max section size, to make sure things propagate correctly _tracker.OnInvalidBlock(invalidBlock, parentBlockHeader.Hash); AssertInvalid(invalidBlock, Keccak.Zero); }
public void givenAnInvalidBlock_WithUnknownParent_thenGetParentFromCache() { IBlockFinder blockFinder = Substitute.For <IBlockFinder>(); IBlockCacheService blockCacheService = new BlockCacheService(); BlockHeader parentBlockHeader = new BlockHeaderBuilder() .TestObject; BlockHeader blockHeader = new BlockHeaderBuilder() .WithParentHash(parentBlockHeader.Hash).TestObject; blockCacheService.BlockCache[blockHeader.Hash] = new Block(blockHeader); blockCacheService.BlockCache[parentBlockHeader.Hash] = new Block(parentBlockHeader); IPoSSwitcher alwaysPos = Substitute.For <IPoSSwitcher>(); alwaysPos.IsPostMerge(Arg.Any <BlockHeader>()).Returns(true); _tracker = new(alwaysPos, blockFinder, blockCacheService, new TestLogManager()); // Small max section size, to make sure things propagate correctly _tracker.OnInvalidBlock(blockHeader.Hash, null); AssertInvalid(blockHeader.Hash, parentBlockHeader.Hash); }
protected override TxReceipt[] ProcessBlock(Block block, IBlockTracer blockTracer, ProcessingOptions options) => _poSSwitcher.IsPostMerge(block.Header) ? PostMergeProcessBlock(block, blockTracer, options) : base.ProcessBlock(block, blockTracer, options);
public AcceptTxResult IsAllowed(Transaction tx, BlockHeader parentHeader) => _poSSwitcher.IsPostMerge(parentHeader) ? _postMergeTxFilter.IsAllowed(tx, parentHeader) : _preMergeTxFilter.IsAllowed(tx, parentHeader);
public override bool Validate(BlockHeader header, BlockHeader?parent, bool isUncle = false) { return(_poSSwitcher.IsPostMerge(header) ? ValidateTheMergeChecks(header) && base.Validate(header, parent, isUncle) : _preMergeHeaderValidator.Validate(header, parent, isUncle)); }
public bool ValidateParams(BlockHeader parent, BlockHeader header) => _poSSwitcher.IsPostMerge(header) || _preMergeSealValidator.ValidateParams(parent, header);