Exemplo n.º 1
0
 public override Task <Empty> UploadTemplate(BytesValue data, ServerCallContext context)
 => Task.Factory.StartNew(() =>
 {
     _logger.LogDebug("UploadTemplate() called with {0} bytes data.", data.Value.Length);
     GetOrCreateWrapper(context).LoadTemplateFromData(data.Value.ToStream());
     return(new Empty());
 });
Exemplo n.º 2
0
 public override ValidationResult ValidateConsensusAfterExecution(BytesValue input)
 {
     return(new ValidationResult
     {
         Success = true
     });
 }
Exemplo n.º 3
0
        internal static ConsensusCommand ToConsensusCommand(this BytesValue bytesValue)
        {
            var consensusCommand = new ConsensusCommand();

            consensusCommand.MergeFrom(bytesValue.Value);
            return(consensusCommand);
        }
        /// <summary>
        /// In this method, `Context.CurrentBlockTime` is the time one miner start request his next consensus command.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override ConsensusCommand GetConsensusCommand(BytesValue input)
        {
            Assert(input.Value.Any(), "Invalid public key.");

            if (Context.CurrentHeight == 1)
            {
                return(GetInvalidConsensusCommand());
            }

            if (!TryToGetCurrentRoundInformation(out var currentRound))
            {
                return(GetInvalidConsensusCommand());
            }

            var publicKey = input.Value.ToHex();

            var behaviour = GetConsensusBehaviour(currentRound, publicKey);

            Context.LogDebug(() => currentRound.ToString(publicKey));

            Context.LogDebug(() => $"Current behaviour: {behaviour.ToString()}");

            return(behaviour == AElfConsensusBehaviour.Nothing
                ? GetInvalidConsensusCommand() // Handle this situation previously.
                : GetConsensusCommand(behaviour, currentRound, publicKey));
        }
        internal static AElfConsensusHeaderInformation ToConsensusHeaderInformation(this BytesValue bytesValue)
        {
            var headerInformation = new AElfConsensusHeaderInformation();

            headerInformation.MergeFrom(bytesValue.Value);
            return(headerInformation);
        }
Exemplo n.º 6
0
        public override BytesValue GetRandomBytes(BytesValue input)
        {
            var height = new Int64Value();

            height.MergeFrom(input.Value);
            return(GetRandomHash(height).ToBytesValue());
        }
        /// <summary>
        /// In this method, `Context.CurrentBlockTime` is the time one miner start request his next consensus command.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override ConsensusCommand GetConsensusCommand(BytesValue input)
        {
            _processingBlockMinerPubkey = input.Value.ToHex();

            if (Context.CurrentHeight < 2)
            {
                return(ConsensusCommandProvider.InvalidConsensusCommand);
            }

            if (!TryToGetCurrentRoundInformation(out var currentRound))
            {
                return(ConsensusCommandProvider.InvalidConsensusCommand);
            }

            if (!currentRound.IsInMinerList(_processingBlockMinerPubkey))
            {
                return(ConsensusCommandProvider.InvalidConsensusCommand);
            }

            var blockchainStartTimestamp = GetBlockchainStartTimestamp();

            var behaviour = IsMainChain
                ? new MainChainConsensusBehaviourProvider(currentRound, _processingBlockMinerPubkey, GetMaximumBlocksCount(),
                                                          Context.CurrentBlockTime, blockchainStartTimestamp, State.TimeEachTerm.Value)
                            .GetConsensusBehaviour()
                : new SideChainConsensusBehaviourProvider(currentRound, _processingBlockMinerPubkey, GetMaximumBlocksCount(),
                                                          Context.CurrentBlockTime).GetConsensusBehaviour();

            Context.LogDebug(() => $"{currentRound.ToString(_processingBlockMinerPubkey)}\nArranged behaviour: {behaviour.ToString()}");

            return(behaviour == AElfConsensusBehaviour.Nothing
                ? ConsensusCommandProvider.InvalidConsensusCommand
                : GetConsensusCommand(behaviour, currentRound, _processingBlockMinerPubkey));
        }
Exemplo n.º 8
0
        public void TestValid()
        {
            var request = new BytesValue {
                Value = ByteString.CopyFrom("Hello", Encoding.Default)
            };

            Client.Bytes(request);
        }
Exemplo n.º 9
0
 public override ConsensusCommand GetConsensusCommand(BytesValue input)
 {
     return(new ConsensusCommand
     {
         ArrangedMiningTime = Context.CurrentBlockTime.AddMilliseconds(1000),
         LimitMillisecondsOfMiningBlock = 1000,
         MiningDueTime = Context.CurrentBlockTime.AddMilliseconds(3000)
     });
 }
Exemplo n.º 10
0
        public void TestInvalid()
        {
            var request = new BytesValue {
                Value = ByteString.Empty
            };
            var exception = Assert.Throws <RpcException>(() => Client.Bytes(request));

            Assert.AreEqual(StatusCode.InvalidArgument, exception.StatusCode, exception.Message);
        }
Exemplo n.º 11
0
 public override Task <BytesValue> Download(Empty _, ServerCallContext context)
 => Task.Factory.StartNew(() =>
 {
     _logger.LogDebug("Download()");
     var ret = new BytesValue {
         Value = ByteString.FromStream(GetOrCreateWrapper(context).Download())
     };
     _logger.LogTrace("  --------------------- Current memory usage: {0} bytes ---------------------", Environment.WorkingSet);
     return(ret);
 });
Exemplo n.º 12
0
 public override TransactionList GenerateConsensusTransactions(BytesValue input)
 {
     return(new TransactionList
     {
         Transactions =
         {
             GenerateTransaction(nameof(Record), new Empty())
         }
     });
 }
Exemplo n.º 13
0
        protected internal virtual void verifyByteArrayValue(IDictionary <string, object> byteArrayValue)
        {
            BytesValue exampleValue = MockProvider.EXAMPLE_HISTORIC_DECISION_BYTE_ARRAY_VALUE;

            assertThat(byteArrayValue, hasEntry("type", (object)VariableValueDto.toRestApiTypeName(exampleValue.Type.Name)));
            string byteString = Base64.encodeBase64String(exampleValue.Value).Trim();

            assertThat(byteArrayValue, hasEntry("value", (object)byteString));
            assertThat(byteArrayValue, hasEntry("valueInfo", (object)Collections.emptyMap()));
        }
 public override BytesValue GetChainInitializationInformation(BytesValue input)
 {
     return(new BytesValue
     {
         Value = new MinerListWithRoundNumber
         {
             MinerList = GetCurrentMinerList(new Empty()),
             RoundNumber = State.CurrentRoundNumber.Value
         }.ToByteString()
     });
 }
        private BytesValue GetConsensusBlockExtraData(BytesValue input, bool isGeneratingTransactions = false)
        {
            var triggerInformation = new AElfConsensusTriggerInformation();

            triggerInformation.MergeFrom(input.Value);

            Assert(triggerInformation.Pubkey.Any(), "Invalid pubkey.");

            if (!TryToGetCurrentRoundInformation(out var currentRound))
            {
                Assert(false, "Failed to get current round information.");
            }

            var publicKeyBytes = triggerInformation.Pubkey;
            var pubkey         = publicKeyBytes.ToHex();

            LogIfPreviousMinerHasNotProduceEnoughTinyBlocks(currentRound, pubkey);

            var information = new AElfConsensusHeaderInformation();

            switch (triggerInformation.Behaviour)
            {
            case AElfConsensusBehaviour.UpdateValue:
                information = GetConsensusExtraDataToPublishOutValue(currentRound, pubkey,
                                                                     triggerInformation);
                if (!isGeneratingTransactions)
                {
                    information.Round = information.Round.GetUpdateValueRound(pubkey);
                }

                break;

            case AElfConsensusBehaviour.TinyBlock:
                information = GetConsensusExtraDataForTinyBlock(currentRound, pubkey,
                                                                triggerInformation);
                break;

            case AElfConsensusBehaviour.NextRound:
                information = GetConsensusExtraDataForNextRound(currentRound, pubkey,
                                                                triggerInformation);
                break;

            case AElfConsensusBehaviour.NextTerm:
                information = GetConsensusExtraDataForNextTerm(pubkey, triggerInformation);
                break;
            }

            if (!isGeneratingTransactions)
            {
                information.Round.DeleteSecretSharingInformation();
            }

            return(information.ToBytesValue());
        }
Exemplo n.º 16
0
        public void BytesWrapper_Standalone()
        {
            ByteString data = ByteString.CopyFrom(1, 2, 3);
            // Can't do this with attributes...
            var parsed   = TextParser.Default.Parse <BytesValue>(WrapInQuotes(data.ToBase64()));
            var expected = new BytesValue {
                Value = data
            };

            Assert.Equal(expected, parsed);
        }
Exemplo n.º 17
0
        public void BytesWrapper_Standalone()
        {
            ByteString data = ByteString.CopyFrom(1, 2, 3);

            // Can't do this with attributes...
            var parsed   = TextParser.Default.Parse <BytesValue>(TextFormatter.EncodeByteString(data));
            var expected = new BytesValue {
                Value = data
            };

            Assert.Equal(expected, parsed);
        }
Exemplo n.º 18
0
        public BytesValue GetTriggerInformationForConsensusTransactions(BytesValue consensusCommandBytes)
        {
            if (consensusCommandBytes == null)
            {
                return(new AElfConsensusTriggerInformation
                {
                    Pubkey = Pubkey,
                    Behaviour = AElfConsensusBehaviour.UpdateValue
                }.ToBytesValue());
            }

            var command = consensusCommandBytes.ToConsensusCommand();
            var hint    = command.Hint.ToAElfConsensusHint();

            if (hint.Behaviour == AElfConsensusBehaviour.UpdateValue)
            {
                var inValue = _inValueCache.GetInValue(hint.RoundId);
                var trigger = new AElfConsensusTriggerInformation
                {
                    Pubkey          = Pubkey,
                    InValue         = inValue,
                    PreviousInValue = _inValueCache.GetInValue(hint.PreviousRoundId),
                    Behaviour       = hint.Behaviour,
                };

                var secretPieces = _secretSharingService.GetEncryptedPieces(hint.RoundId);
                foreach (var secretPiece in secretPieces)
                {
                    trigger.EncryptedPieces.Add(secretPiece.Key, ByteString.CopyFrom(secretPiece.Value));
                }

                var decryptedPieces = _secretSharingService.GetDecryptedPieces(hint.RoundId);
                foreach (var decryptedPiece in decryptedPieces)
                {
                    trigger.DecryptedPieces.Add(decryptedPiece.Key, ByteString.CopyFrom(decryptedPiece.Value));
                }

                var revealedInValues = _secretSharingService.GetRevealedInValues(hint.RoundId);
                foreach (var revealedInValue in revealedInValues)
                {
                    trigger.RevealedInValues.Add(revealedInValue.Key, revealedInValue.Value);
                }

                return(trigger.ToBytesValue());
            }

            return(new AElfConsensusTriggerInformation
            {
                Pubkey = Pubkey,
                Behaviour = hint.Behaviour
            }.ToBytesValue());
        }
Exemplo n.º 19
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (valueTypeCase_ == ValueTypeOneofCase.NullValue)
            {
                hash ^= NullValue.GetHashCode();
            }
            if (valueTypeCase_ == ValueTypeOneofCase.BooleanValue)
            {
                hash ^= BooleanValue.GetHashCode();
            }
            if (valueTypeCase_ == ValueTypeOneofCase.IntegerValue)
            {
                hash ^= IntegerValue.GetHashCode();
            }
            if (valueTypeCase_ == ValueTypeOneofCase.DoubleValue)
            {
                hash ^= DoubleValue.GetHashCode();
            }
            if (valueTypeCase_ == ValueTypeOneofCase.TimestampValue)
            {
                hash ^= TimestampValue.GetHashCode();
            }
            if (valueTypeCase_ == ValueTypeOneofCase.StringValue)
            {
                hash ^= StringValue.GetHashCode();
            }
            if (valueTypeCase_ == ValueTypeOneofCase.BytesValue)
            {
                hash ^= BytesValue.GetHashCode();
            }
            if (valueTypeCase_ == ValueTypeOneofCase.ReferenceValue)
            {
                hash ^= ReferenceValue.GetHashCode();
            }
            if (valueTypeCase_ == ValueTypeOneofCase.GeoPointValue)
            {
                hash ^= GeoPointValue.GetHashCode();
            }
            if (valueTypeCase_ == ValueTypeOneofCase.ArrayValue)
            {
                hash ^= ArrayValue.GetHashCode();
            }
            if (valueTypeCase_ == ValueTypeOneofCase.MapValue)
            {
                hash ^= MapValue.GetHashCode();
            }
            hash ^= (int)valueTypeCase_;
            return(hash);
        }
Exemplo n.º 20
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (column_ != null)
            {
                hash ^= Column.GetHashCode();
            }
            if (NegateComparator != false)
            {
                hash ^= NegateComparator.GetHashCode();
            }
            if (Comparator != global::LukeKennedy.LSQL.Net.Comparator.UnknownComparator)
            {
                hash ^= Comparator.GetHashCode();
            }
            if (valueCase_ == ValueOneofCase.StringValue)
            {
                hash ^= StringValue.GetHashCode();
            }
            if (valueCase_ == ValueOneofCase.Int64Value)
            {
                hash ^= Int64Value.GetHashCode();
            }
            if (valueCase_ == ValueOneofCase.Uint64Value)
            {
                hash ^= Uint64Value.GetHashCode();
            }
            if (valueCase_ == ValueOneofCase.DoubleValue)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleValue);
            }
            if (valueCase_ == ValueOneofCase.BoolValue)
            {
                hash ^= BoolValue.GetHashCode();
            }
            if (valueCase_ == ValueOneofCase.BytesValue)
            {
                hash ^= BytesValue.GetHashCode();
            }
            if (valueCase_ == ValueOneofCase.TimeValue)
            {
                hash ^= TimeValue.GetHashCode();
            }
            hash ^= (int)valueCase_;
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Exemplo n.º 21
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Type != 0)
            {
                hash ^= Type.GetHashCode();
            }
            if (valueCase_ == ValueOneofCase.IntValue)
            {
                hash ^= IntValue.GetHashCode();
            }
            if (valueCase_ == ValueOneofCase.LongIntValue)
            {
                hash ^= LongIntValue.GetHashCode();
            }
            if (valueCase_ == ValueOneofCase.BoolValue)
            {
                hash ^= BoolValue.GetHashCode();
            }
            if (valueCase_ == ValueOneofCase.StringValue)
            {
                hash ^= StringValue.GetHashCode();
            }
            if (valueCase_ == ValueOneofCase.BytesValue)
            {
                hash ^= BytesValue.GetHashCode();
            }
            if (valueCase_ == ValueOneofCase.FloatValue)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(FloatValue);
            }
            if (valueCase_ == ValueOneofCase.DoubleValue)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleValue);
            }
            if (ObjectTypeId != 0)
            {
                hash ^= ObjectTypeId.GetHashCode();
            }
            hash ^= (int)valueCase_;
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Converts the serialized protobuf data to human friendly representation.
        /// </summary>
        /// <returns></returns>
        public byte[] ToFriendlyBytes()
        {
            switch (Type)
            {
            case Types.RetType.Bool:
                var boolval = new BoolValue();
                ((IMessage)boolval).MergeFrom(this.Data);
                return(BitConverter.GetBytes(boolval.Value));

            case Types.RetType.Int32:
                var sint32Val = new SInt32Value();
                ((IMessage)sint32Val).MergeFrom(this.Data);
                return(GetFriendlyBytes(sint32Val.Value));

            case Types.RetType.Uint32:
                var uint32Val = new UInt32Value();
                ((IMessage)uint32Val).MergeFrom(this.Data);
                return(GetFriendlyBytes(uint32Val.Value));

            case Types.RetType.Int64:
                var sint64Val = new SInt64Value();
                ((IMessage)sint64Val).MergeFrom(this.Data);
                return(GetFriendlyBytes(sint64Val.Value));

            case Types.RetType.Uint64:
                var uint64Val = new UInt64Value();
                ((IMessage)uint64Val).MergeFrom(this.Data);
                return(GetFriendlyBytes(uint64Val.Value));

            case Types.RetType.String:
                var stringVal = new StringValue();
                ((IMessage)stringVal).MergeFrom(this.Data);
                return(GetFriendlyBytes(stringVal.Value));

            case Types.RetType.Bytes:
                var bytesVal = new BytesValue();
                ((IMessage)bytesVal).MergeFrom(this.Data);
                return(GetFriendlyBytes(bytesVal.Value.ToByteArray()));

            case Types.RetType.PbMessage:
            case Types.RetType.UserType:
                // Both are treated as bytes
                return(GetFriendlyBytes(Data.ToByteArray()));
            }

            return(new byte[0]);
        }
Exemplo n.º 23
0
        /// <summary>
        /// In this method, `Context.CurrentBlockTime` is the time one miner start request his next consensus command.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override ConsensusCommand GetConsensusCommand(BytesValue input)
        {
            _processingBlockMinerPubkey = input.Value.ToHex();

            if (Context.CurrentHeight < 2)
            {
                return(ConsensusCommandProvider.InvalidConsensusCommand);
            }

            if (!TryToGetCurrentRoundInformation(out var currentRound))
            {
                return(ConsensusCommandProvider.InvalidConsensusCommand);
            }

            if (!currentRound.IsInMinerList(_processingBlockMinerPubkey))
            {
                return(ConsensusCommandProvider.InvalidConsensusCommand);
            }

            if (currentRound.RealTimeMinersInformation.Count != 1 &&
                currentRound.RoundNumber > 2 &&
                State.LatestPubkeyToTinyBlocksCount.Value != null &&
                State.LatestPubkeyToTinyBlocksCount.Value.Pubkey == _processingBlockMinerPubkey &&
                State.LatestPubkeyToTinyBlocksCount.Value.BlocksCount < 0)
            {
                return(GetConsensusCommand(AElfConsensusBehaviour.NextRound, currentRound, _processingBlockMinerPubkey,
                                           Context.CurrentBlockTime));
            }

            var blockchainStartTimestamp = GetBlockchainStartTimestamp();

            var behaviour = IsMainChain
                ? new MainChainConsensusBehaviourProvider(currentRound, _processingBlockMinerPubkey,
                                                          GetMaximumBlocksCount(),
                                                          Context.CurrentBlockTime, blockchainStartTimestamp, State.PeriodSeconds.Value)
                            .GetConsensusBehaviour()
                : new SideChainConsensusBehaviourProvider(currentRound, _processingBlockMinerPubkey,
                                                          GetMaximumBlocksCount(),
                                                          Context.CurrentBlockTime).GetConsensusBehaviour();

            Context.LogDebug(() =>
                             $"{currentRound.ToString(_processingBlockMinerPubkey)}\nArranged behaviour: {behaviour.ToString()}");

            return(behaviour == AElfConsensusBehaviour.Nothing
                ? ConsensusCommandProvider.InvalidConsensusCommand
                : GetConsensusCommand(behaviour, currentRound, _processingBlockMinerPubkey, Context.CurrentBlockTime));
        }
Exemplo n.º 24
0
        public async Task TestRoundtrip()
        {
            var bytes  = new byte[1024 * 1024];
            var random = new Random();

            random.NextBytes(bytes);

            var client  = new HttpClient(new Base64Handler());
            var request = new BytesValue {
                Value = ByteString.CopyFrom(bytes)
            };
            var uri = $"http://{EndPoint}/Echo/Bytes";

            var response = await client.PostGrpcWebAsync <BytesValue, BytesValue>(uri, request);

            Assert.AreEqual(request.Value.ToByteArray(), response.Value.ToByteArray());
        }
Exemplo n.º 25
0
        public override TransactionList GenerateConsensusTransactions(BytesValue input)
        {
            var triggerInformation = new AElfConsensusTriggerInformation();

            triggerInformation.MergeFrom(input.Value);
            // Some basic checks.
            Assert(triggerInformation.Pubkey.Any(),
                   "Data to request consensus information should contain pubkey.");

            var pubkey = triggerInformation.Pubkey;
            var consensusInformation = new AElfConsensusHeaderInformation();

            consensusInformation.MergeFrom(GetConsensusBlockExtraData(input, true).Value);
            var transactionList = GenerateTransactionListByExtraData(consensusInformation, pubkey);

            return(transactionList);
        }
Exemplo n.º 26
0
                public override int GetHashCode()
                {
                    int hash = 1;

                    if (BytesValue.Length != 0)
                    {
                        hash ^= BytesValue.GetHashCode();
                    }
                    if (StringValue.Length != 0)
                    {
                        hash ^= StringValue.GetHashCode();
                    }
                    if (_unknownFields != null)
                    {
                        hash ^= _unknownFields.GetHashCode();
                    }
                    return(hash);
                }
Exemplo n.º 27
0
                public override int GetHashCode()
                {
                    int hash = 1;

                    if (Type != 0)
                    {
                        hash ^= Type.GetHashCode();
                    }
                    if (valueCase_ == ValueOneofCase.Int32Value)
                    {
                        hash ^= Int32Value.GetHashCode();
                    }
                    if (valueCase_ == ValueOneofCase.Int64Value)
                    {
                        hash ^= Int64Value.GetHashCode();
                    }
                    if (valueCase_ == ValueOneofCase.FloatValue)
                    {
                        hash ^= FloatValue.GetHashCode();
                    }
                    if (valueCase_ == ValueOneofCase.DoubleValue)
                    {
                        hash ^= DoubleValue.GetHashCode();
                    }
                    if (valueCase_ == ValueOneofCase.BooleanValue)
                    {
                        hash ^= BooleanValue.GetHashCode();
                    }
                    if (valueCase_ == ValueOneofCase.StringValue)
                    {
                        hash ^= StringValue.GetHashCode();
                    }
                    if (valueCase_ == ValueOneofCase.BytesValue)
                    {
                        hash ^= BytesValue.GetHashCode();
                    }
                    if (valueCase_ == ValueOneofCase.MetaValue)
                    {
                        hash ^= MetaValue.GetHashCode();
                    }
                    hash ^= (int)valueCase_;
                    return(hash);
                }
        public override BytesValue GetRandomBytes(BytesValue input)
        {
            var serializedInput = new GetRandomBytesInput();

            serializedInput.MergeFrom(input.Value);
            var value = new Hash();

            value.MergeFrom(serializedInput.Value);
            var randomHashFromContext = Context.GetRandomHash(value);

            return(new BytesValue
            {
                Value = serializedInput.Kind == 1
                    ? new BytesValue {
                    Value = randomHashFromContext.Value
                }.ToByteString()
                    : new Int64Value {
                    Value = Context.ConvertHashToInt64(randomHashFromContext, 1, 10000)
                }.ToByteString()
            });
        }
        public override Empty UpdateInformationFromCrossChain(BytesValue input)
        {
            Assert(
                Context.Sender == Context.GetContractAddressByName(SmartContractConstants.CrossChainContractSystemName),
                "Only Cross Chain Contract can call this method.");

            Assert(!State.IsMainChain.Value, "Only side chain can update consensus information.");

            // For now we just extract the miner list from main chain consensus information, then update miners list.
            if (input == null || input.Value.IsEmpty)
            {
                return(new Empty());
            }

            var consensusInformation = AElfConsensusHeaderInformation.Parser.ParseFrom(input.Value);

            // check round number of shared consensus, not term number
            if (consensusInformation.Round.RoundNumber <= State.MainChainRoundNumber.Value)
            {
                return(new Empty());
            }

            Context.LogDebug(() =>
                             $"Shared miner list of round {consensusInformation.Round.RoundNumber}:" +
                             $"{consensusInformation.Round.ToString("M")}");

            DistributeResourceTokensToPreviousMiners();

            State.MainChainRoundNumber.Value = consensusInformation.Round.RoundNumber;

            var minersKeys = consensusInformation.Round.RealTimeMinersInformation.Keys;

            State.MainChainCurrentMinerList.Value = new MinerList
            {
                Pubkeys = { minersKeys.Select(ByteStringHelper.FromHexString) }
            };

            return(new Empty());
        }
Exemplo n.º 30
0
        public override ValidationResult ValidateConsensusAfterExecution(BytesValue input)
        {
            var headerInformation = new AElfConsensusHeaderInformation();

            headerInformation.MergeFrom(input.Value);
            if (TryToGetCurrentRoundInformation(out var currentRound))
            {
                if (headerInformation.Behaviour == AElfConsensusBehaviour.UpdateValue)
                {
                    headerInformation.Round =
                        currentRound.RecoverFromUpdateValue(headerInformation.Round,
                                                            headerInformation.SenderPubkey.ToHex());
                }

                if (headerInformation.Behaviour == AElfConsensusBehaviour.TinyBlock)
                {
                    headerInformation.Round =
                        currentRound.RecoverFromTinyBlock(headerInformation.Round,
                                                          headerInformation.SenderPubkey.ToHex());
                }

                var isContainPreviousInValue = !currentRound.IsMinerListJustChanged;
                if (headerInformation.Round.GetHash(isContainPreviousInValue) !=
                    currentRound.GetHash(isContainPreviousInValue))
                {
                    Context.LogDebug(() => $"Round information of block header:\n{headerInformation.Round}");
                    Context.LogDebug(() => $"Round information of executing result:\n{currentRound}");
                    return(new ValidationResult
                    {
                        Success = false, Message = "Current round information is different with consensus extra data."
                    });
                }
            }

            return(new ValidationResult {
                Success = true
            });
        }