Beispiel #1
0
        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());
        }
Beispiel #2
0
 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());
 }
Beispiel #3
0
 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());
 }
Beispiel #4
0
 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])
         }
     });
 }
Beispiel #5
0
 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));
 }
Beispiel #6
0
 public ConsensusService(NeoSystem system, Wallet wallet)
 {
     this.system  = system;
     this.context = new ConsensusContext(wallet);
 }