public async Task SyncByBlock_Success() { var response = await _networkService.GetBlockByHashAsync(HashHelper.ComputeFrom("PeerBlock"), null); var peerBlock = response.Payload; var block = await _blockchainService.GetBlockByHashAsync(peerBlock.GetHash()); block.ShouldBeNull(); var chain = await _blockchainService.GetChainAsync(); await _blockSyncService.SyncByBlockAsync(chain, new SyncBlockDto { BlockWithTransactions = peerBlock, BatchRequestBlockCount = 5 }); block = await _blockchainService.GetBlockByHashAsync(peerBlock.GetHash()); block.GetHash().ShouldBe(peerBlock.GetHash()); chain = await _blockchainService.GetChainAsync(); chain.BestChainHash.ShouldBe(peerBlock.GetHash()); chain.BestChainHeight.ShouldBe(peerBlock.Height); }
private async Task ProcessNewBlockAsync(BlockWithTransactions blockWithTransactions, string senderPubkey) { var chain = await _blockchainService.GetChainAsync(); if (!await _blockSyncValidationService.ValidateBlockBeforeSyncAsync(chain, blockWithTransactions, senderPubkey)) { return; } await _blockSyncService.SyncByBlockAsync(chain, new SyncBlockDto { BlockWithTransactions = blockWithTransactions, BatchRequestBlockCount = _blockSyncOptions.MaxBatchRequestBlockCount, SuggestedPeerPubkey = senderPubkey }); }
private async Task ProcessNewBlockAsync(BlockWithTransactions blockWithTransactions, string senderPubkey) { Logger.LogDebug($"Start full block sync job, block: {blockWithTransactions}, peer: {senderPubkey}."); var chain = await _blockchainService.GetChainAsync(); if (!await _blockSyncValidationService.ValidateBlockAsync(chain, blockWithTransactions, senderPubkey)) { return; } await _blockSyncService.SyncByBlockAsync(chain, new SyncBlockDto { BlockWithTransactions = blockWithTransactions, BatchRequestBlockCount = _blockSyncOptions.MaxBatchRequestBlockCount, SuggestedPeerPubkey = senderPubkey }); }