src/Stratis.FederatedPeg.Features.FederationGateway/TargetChain/MaturedBlocksSyncManager.cs
/// <summary>Asks for blocks from another gateway node and then processes them.</summary>
/// <returns><c>true</c> if delay between next time we should ask for blocks is required; <c>false</c> otherwise.</returns>
/// <exception cref="OperationCanceledException">Thrown when <paramref name="cancellationToken"/> is cancelled.</exception>
Asks for blocks from another gateway node and then processes them.
Asks for blocks from another gateway node and then processes them .
protected async Task<bool> SyncBatchOfBlocksAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            int blocksToRequest = 1;
            if (!this.store.HasSuspended())
                blocksToRequest = MaxBlocksToRequest;
            var model = new MaturedBlockRequestModel(this.store.NextMatureDepositHeight, blocksToRequest);
            this.logger.LogDebug("Request model created: {0}:{1}, {2}:{3}.", nameof(model.BlockHeight), model.BlockHeight,
                nameof(model.MaxBlocksToSend), model.MaxBlocksToSend);
            IList<MaturedBlockDepositsModel> matureBlockDeposits = await this.federationGatewayClient.GetMaturedBlockDepositsAsync(model, cancellationToken).ConfigureAwait(false);
            bool delayRequired = true;
            if (matureBlockDeposits != null)
            {
                foreach (MaturedBlockDepositsModel maturedBlockDeposit in matureBlockDeposits)
                {
                    foreach (IDeposit deposit in maturedBlockDeposit.Deposits)
                    {
                        this.logger.LogDebug("New deposit received BlockNumber={0}, TargetAddress='{1}', depositId='{2}', Amount='{3}'.",
                            deposit.BlockNumber, deposit.TargetAddress, deposit.Id, deposit.Amount);
                    }
                }
                if (matureBlockDeposits.Count > 0)
                {
                    bool success = await this.store.RecordLatestMatureDepositsAsync(matureBlockDeposits).ConfigureAwait(false);
                    if (success)
                        delayRequired = false;
                }
                else
                {
                    this.logger.LogDebug("Considering ourselves fully synced since no blocks were received");
                    await this.store.SaveCurrentTipAsync().ConfigureAwait(false);
                }
            }
            return delayRequired;
        }
protected async Task < bool > SyncBatchOfBlocksAsync ( CancellationToken cancellationToken = default ( CancellationToken ) ) { int blocksToRequest = 1 ; if ( ! this . store . HasSuspended ( ) ) blocksToRequest = MaxBlocksToRequest ; var model = new MaturedBlockRequestModel ( this . store . NextMatureDepositHeight , blocksToRequest ) ; this . logger . LogDebug ( " " , nameof ( model . BlockHeight ) , model . BlockHeight , nameof ( model . MaxBlocksToSend ) , model . MaxBlocksToSend ) ; IList < MaturedBlockDepositsModel > matureBlockDeposits = await this . federationGatewayClient . GetMaturedBlockDepositsAsync ( model , cancellationToken ) . ConfigureAwait ( false ) ; bool delayRequired = true ; if ( matureBlockDeposits != null ) { foreach ( MaturedBlockDepositsModel maturedBlockDeposit in matureBlockDeposits ) { foreach ( IDeposit deposit in maturedBlockDeposit . Deposits ) { this . logger . LogDebug ( " " , deposit . BlockNumber , deposit . TargetAddress , deposit . Id , deposit . Amount ) ; } } if ( matureBlockDeposits . Count > 0 ) { bool success = await this . store . RecordLatestMatureDepositsAsync ( matureBlockDeposits ) . ConfigureAwait ( false ) ; if ( success ) delayRequired = false ; } else { this . logger . LogDebug ( " " ) ; await this . store . SaveCurrentTipAsync ( ) . ConfigureAwait ( false ) ; } } return delayRequired ; }
Asks for blocks from another gateway node and then processes them.
Asks for blocks from another gateway node and then processes them .
// TODO why are we asking for max of 1 block and if it's not suspended then 1000? investigate this logic in maturedBlocksProvider // TODO investigate if we can ask for blocks that are reorgable. If so it's a problem and an attack vector. // API method that provides blocks should't give us blocks that are not mature! // Ask for blocks. // Log what we've received. // If we received a portion of blocks we can ask for new portion without any delay. // If we've received nothing we assume we are at the tip and should flush. // Same mechanic as with syncing headers protocol.
None
Thrown when  is cancelled.
Thrown when is cancelled .
cancellationToken
CancellationToken