/// <summary> /// Constructor. /// </summary> /// <param name="kvPropertyService">Key-value property service.</param> /// /// <param name="consensusContext">Consensus context.</param> public KvPropertiesController( IKvPropertyService kvPropertyService, IConsensusContext consensusContext) { _kvPropertyService = kvPropertyService; _consensusContext = consensusContext; }
public ConsensusPayload[] GetPrepareResponsePayloads(IConsensusContext context, ConsensusPayload payload) { UInt256 preparationHash = PreparationHash ?? context.PreparationPayloads[context.PrimaryIndex]?.Hash; if (preparationHash is null) { return(new ConsensusPayload[0]); } return(PreparationMessages.Values.Where(p => p.ValidatorIndex != context.PrimaryIndex).Select(p => new ConsensusPayload { Version = payload.Version, PrevHash = payload.PrevHash, BlockIndex = payload.BlockIndex, ValidatorIndex = p.ValidatorIndex, ConsensusMessage = new PrepareResponse { ViewNumber = ViewNumber, PreparationHash = preparationHash }, Witness = new Witness { InvocationScript = p.InvocationScript, VerificationScript = Contract.CreateSignatureRedeemScript(context.Validators[p.ValidatorIndex]) } }).ToArray()); }
public Candidate(IConsensusContext consensusContext, ILogger <IConsensusContext> logger) { _consensusContext = consensusContext; _logger = logger; ClearVoteGranted(); }
public ConsensusService(IActorRef localNode, IActorRef taskManager, IConsensusContext context) { this.localNode = localNode; this.taskManager = taskManager; this.context = context; Context.System.EventStream.Subscribe(Self, typeof(Blockchain.PersistCompleted)); }
public Leader(IConsensusContext consensusContext, ILogger <IConsensusContext> logger) { _consensusContext = consensusContext; _logger = logger; _consensusContext.NodeVote.LeaderNode = _consensusContext.CurrentNode; _consensusContext.NodeVote.VoteTerm = 0; }
public static ulong GetNonce(this IConsensusContext context) { byte[] nonce = new byte[sizeof(ulong)]; Random rand = new Random(); rand.NextBytes(nonce); return(nonce.ToUInt64(0)); }
public LogReplication( IConsensusContext consensusContext, HttpClient httpClient, ILogger <LogReplication> logger) { _consensusContext = consensusContext; _httpClient = httpClient; _logger = logger; }
/// <summary> /// Constructor. /// </summary> /// <param name="servicesService">Services service.</param> /// <param name="serviceHealthService">Searvices health service.</param> /// <param name="consensusContext">Context of consensus protocol.</param> public ServicesController( IServicesService servicesService, IServiceHealthService serviceHealthService, IConsensusContext consensusContext) { _servicesService = servicesService; _serviceHealthService = serviceHealthService; _consensusContext = consensusContext; }
public ConsensusService(IActorRef localNode, IActorRef taskManager, Wallet wallet, UInt160 chainHash) { this.chainHash = chainHash; this.localNode = localNode; this.taskManager = taskManager; this.blockchain = ZoroChainSystem.Singleton.AskBlockchain(chainHash); this.localNodeObj = ZoroChainSystem.Singleton.AskLocalNode(chainHash); this.context = new ConsensusContext(blockchain, wallet); Context.System.EventStream.Subscribe(Self, typeof(Blockchain.PersistCompleted)); }
public KvPropertyService( IRepository <KvProperty> kvPropertyRepository, IKvPropertyValidator kvPropertyValidator, ILogReplication logReplication, IConsensusContext consensusContext) { _kvPropertyRepository = kvPropertyRepository; _kvPropertyValidator = kvPropertyValidator; _logReplication = logReplication; _consensusContext = consensusContext; }
public ServicesService( IRepository <Service> serviceRepository, IServiceValidator serviceValidator, IMemoryCache memoryCache, IServiceHealthWorker serviceHealthWorker, ILogReplication logReplication, IConsensusContext consensusContext) { _serviceRepository = serviceRepository; _serviceValidator = serviceValidator; _memoryCache = memoryCache; _serviceHealthWorker = serviceHealthWorker; _logReplication = logReplication; _consensusContext = consensusContext; }
private static ConsensusPayload MakeSignedPayload(IConsensusContext context, ConsensusMessage message, ushort validatorIndex, byte[] witnessInvocationScript) { return(new ConsensusPayload { Version = ConsensusContext.Version, PrevHash = context.PrevHash, BlockIndex = context.BlockIndex, ValidatorIndex = validatorIndex, ConsensusMessage = message, Witness = new Witness { InvocationScript = witnessInvocationScript, VerificationScript = Contract.CreateSignatureRedeemScript(context.Validators[validatorIndex]) } }); }
public ConsensusPayload[] GetChangeViewPayloads(IConsensusContext 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()); }
public ConsensusPayload[] GetCommitPayloadsFromRecoveryMessage(IConsensusContext 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()); }
public static bool Load(this IConsensusContext context, Store store) { byte[] data = store.Get(CN_Context, new byte[0]); if (data is null || data.Length == 0) { return(false); } using (MemoryStream ms = new MemoryStream(data, false)) using (BinaryReader reader = new BinaryReader(ms)) { try { context.Deserialize(reader); } catch { return(false); } return(true); } }
public ConsensusPayload GetPrepareRequestPayload(IConsensusContext context, ConsensusPayload payload) { if (PrepareRequestMessage == null) { return(null); } if (!PreparationMessages.TryGetValue((int)context.PrimaryIndex, out RecoveryMessage.PreparationPayloadCompact compact)) { return(null); } return(new ConsensusPayload { Version = payload.Version, PrevHash = payload.PrevHash, BlockIndex = payload.BlockIndex, ValidatorIndex = (ushort)context.PrimaryIndex, ConsensusMessage = PrepareRequestMessage, Witness = new Witness { InvocationScript = compact.InvocationScript, VerificationScript = Contract.CreateSignatureRedeemScript(context.Validators[context.PrimaryIndex]) } }); }
public static uint GetPrimaryIndex(this IConsensusContext context, byte viewNumber) { int p = ((int)context.BlockIndex - viewNumber) % context.Validators.Length; return(p >= 0 ? (uint)p : (uint)(p + context.Validators.Length)); }
// A possible attack can happen if the last node to commit is malicious and either sends change view after his // commit to stall nodes in a higher view, or if he refuses to send recovery messages. In addition, if a node // asking change views loses network or crashes and comes back when nodes are committed in more than one higher // numbered view, it is possible for the node accepting recovery and commit in any of the higher views, thus // potentially splitting nodes among views and stalling the network. public static bool MoreThanFNodesCommitted(this IConsensusContext context) => context.CommitPayloads.Count(p => p != null) > context.F();
public static bool NotAcceptingPayloadsDueToViewChanging(this IConsensusContext context) => context.ViewChanging() && !context.MoreThanFNodesCommitted();
public static bool ViewChanging(this IConsensusContext context) => !context.WatchOnly() && context.ChangeViewPayloads[context.MyIndex]?.GetDeserializedMessage <ChangeView>().NewViewNumber > context.ViewNumber;
public static bool BlockSent(this IConsensusContext context) => context.Block != null;
public static bool CommitSent(this IConsensusContext context) => !context.WatchOnly() && context.CommitPayloads[context.MyIndex] != null;
public static bool RequestSentOrReceived(this IConsensusContext context) => context.PreparationPayloads[context.PrimaryIndex] != null;
public static Header PrevHeader(this IConsensusContext context) => context.Snapshot.GetHeader(context.PrevHash);
public static bool WatchOnly(this IConsensusContext context) => context.MyIndex < 0;
public Follower(IConsensusContext consensusContext, ILogger <IConsensusContext> logger) { _consensusContext = consensusContext; _logger = logger; }
public static bool IsPrimary(this IConsensusContext context) => context.MyIndex == context.PrimaryIndex;
public static bool ResponseSent(this IConsensusContext context) => !context.WatchOnly() && context.PreparationPayloads[context.MyIndex] != null;
public ConsensusService(IActorRef localNode, IActorRef taskManager, IConsensusContext context) { this.localNode = localNode; this.taskManager = taskManager; this.context = context; }
public static bool IsBackup(this IConsensusContext context) => context.MyIndex >= 0 && context.MyIndex != context.PrimaryIndex;