private void OnConsensusPayload(ConsensusPayload payload) { if (payload.ValidatorIndex == context.MyIndex) { return; } if (payload.Version != ConsensusContext.Version) { return; } if (payload.PrevHash != context.PrevHash || payload.BlockIndex != context.BlockIndex) { if (context.Snapshot.Height + 1 < payload.BlockIndex) { Log($"chain sync: expected={payload.BlockIndex} current: {context.Snapshot.Height} nodes={localNode.ConnectedCount}", LogLevel.Warning); } return; } if (payload.ValidatorIndex >= context.Validators.Length) { return; } ConsensusMessage message; try { message = ConsensusMessage.DeserializeFrom(payload.Data); } catch { return; } if (message.ViewNumber != context.ViewNumber && message.Type != ConsensusMessageType.ChangeView) { return; } switch (message.Type) { case ConsensusMessageType.ChangeView: OnChangeViewReceived(payload, (ChangeView)message); break; case ConsensusMessageType.PrepareRequest: OnPrepareRequestReceived(payload, (PrepareRequest)message); break; case ConsensusMessageType.PrepareResponse: OnPrepareResponseReceived(payload, (PrepareResponse)message); break; } }
private void OnConsensusPayload(ConsensusPayload payload) { if (payload.ValidatorIndex == context.MyIndex) { return; } if (payload.Version != ConsensusContext.Version) { return; } if (payload.PrevHash != context.PrevHash || payload.BlockIndex != context.BlockIndex) { if (context.BlockIndex != payload.BlockIndex) { Log($"chain sync: expected={payload.BlockIndex} current={context.BlockIndex} nodes={localNodeObj.ConnectedCount}", LogLevel.Warning); if (context.BlockIndex < payload.BlockIndex) { AddUnhandledPayloadToCache(payload); } } if (payload.BlockIndex == context.BlockIndex && payload.PrevHash != context.PrevHash) { Log($"block hash unmatched: sender={payload.ValidatorIndex} remote={payload.PrevHash} local={context.PrevHash}", LogLevel.Error); } return; } if (context.State.HasFlag(ConsensusState.BlockSent)) { return; } if (payload.ValidatorIndex >= context.Validators.Length) { return; } ConsensusMessage message; try { message = ConsensusMessage.DeserializeFrom(payload.Data); } catch { return; } if (message.ViewNumber != context.ViewNumber && message.Type != ConsensusMessageType.ChangeView) { return; } switch (message.Type) { case ConsensusMessageType.ChangeView: OnChangeViewReceived(payload, (ChangeView)message); break; case ConsensusMessageType.PrepareRequest: OnPrepareRequestReceived(payload, (PrepareRequest)message); break; case ConsensusMessageType.PrepareResponse: OnPrepareResponseReceived(payload, (PrepareResponse)message); break; } }