internal ExtensiblePayload[] GetPrepareResponsePayloads(ConsensusContext context) { UInt256 preparationHash = PreparationHash ?? context.PreparationPayloads[context.Block.PrimaryIndex]?.Hash; if (preparationHash is null) { return(Array.Empty <ExtensiblePayload>()); } return(PreparationMessages.Values.Where(p => p.ValidatorIndex != context.Block.PrimaryIndex).Select(p => context.CreatePayload(new PrepareResponse { BlockIndex = BlockIndex, ValidatorIndex = p.ValidatorIndex, ViewNumber = ViewNumber, PreparationHash = preparationHash }, p.InvocationScript)).ToArray()); }
internal ConsensusPayload[] GetCommitPayloadsFromRecoveryMessage(ConsensusContext context, ConsensusPayload payload) { return(CommitMessages.Values.Select(p => new ConsensusPayload { Version = payload.Version, PrevHash = payload.PrevHash, BlockIndex = payload.BlockIndex, ValidatorIndex = p.ValidatorIndex, ConsensusMessage = new Commit { ViewNumber = p.ViewNumber, Signature = p.Signature }, Witness = new Witness { InvocationScript = p.InvocationScript, VerificationScript = Contract.CreateSignatureRedeemScript(context.Validators[p.ValidatorIndex]) } }).ToArray()); }
internal ConsensusPayload[] GetChangeViewPayloads(ConsensusContext context, ConsensusPayload payload) { return(ChangeViewMessages.Values.Select(p => new ConsensusPayload { Version = payload.Version, PrevHash = payload.PrevHash, BlockIndex = payload.BlockIndex, ValidatorIndex = p.ValidatorIndex, ConsensusMessage = new ChangeView { ViewNumber = p.OriginalViewNumber, Timestamp = p.Timestamp }, Witness = new Witness { InvocationScript = p.InvocationScript, VerificationScript = Contract.CreateSignatureRedeemScript(context.Validators[p.ValidatorIndex]) } }).ToArray()); }
internal ConsensusPayload GetPrepareRequestPayload(ConsensusContext context, ConsensusPayload payload) { if (PrepareRequestMessage == null) { return(null); } if (!PreparationMessages.TryGetValue((int)context.Block.ConsensusData.PrimaryIndex, out RecoveryMessage.PreparationPayloadCompact compact)) { return(null); } return(new ConsensusPayload { Version = payload.Version, PrevHash = payload.PrevHash, BlockIndex = payload.BlockIndex, ValidatorIndex = (ushort)context.Block.ConsensusData.PrimaryIndex, ConsensusMessage = PrepareRequestMessage, Witness = new Witness { InvocationScript = compact.InvocationScript, VerificationScript = Contract.CreateSignatureRedeemScript(context.Validators[context.Block.ConsensusData.PrimaryIndex]) } }); }
internal ConsensusService(IActorRef localNode, IActorRef taskManager, IActorRef blockchain, ConsensusContext context) { this.localNode = localNode; this.taskManager = taskManager; this.blockchain = blockchain; this.context = context; Context.System.EventStream.Subscribe(Self, typeof(Blockchain.PersistCompleted)); Context.System.EventStream.Subscribe(Self, typeof(Blockchain.RelayResult)); }
public ConsensusService(NeoSystem system, Wallet wallet) { this.system = system; this.context = new ConsensusContext(wallet); }