public static async Task <T> GetBlockExecutedDataAsync <T>(
            this IBlockchainExecutedDataService blockchainExecutedDataService,
            IBlockIndex chainContext, string key)
        {
            var byteString = await blockchainExecutedDataService.GetBlockExecutedDataAsync(chainContext, key);

            return(SerializationHelper.Deserialize <T>(byteString?.ToByteArray()));
        }
 public async Task SetSmartContractAddressAsync(IBlockIndex blockIndex, string contractName, Address address)
 {
     await AddBlockExecutedDataAsync(blockIndex, contractName, new SmartContractAddress
     {
         Address     = address,
         BlockHash   = blockIndex.BlockHash,
         BlockHeight = blockIndex.BlockHeight
     });
 }
Example #3
0
        public async Task SetLimitAsync(IBlockIndex blockIndex, int limit)
        {
            var blockTransactionLimit = new BlockTransactionLimit
            {
                Value = limit
            };

            await AddBlockExecutedDataAsync(blockIndex, blockTransactionLimit);
        }
 public static async Task AddBlockExecutedDataAsync <T>(
     this ICachedBlockchainExecutedDataService <T> cachedBlockchainExecutedDataGettingService,
     IBlockIndex blockIndex, string key, T blockExecutedData)
 {
     var dic = new Dictionary <string, T>
     {
         { key, blockExecutedData }
     };
     await cachedBlockchainExecutedDataGettingService.AddBlockExecutedDataAsync(blockIndex, dic);
 }
        public async Task SetStateSizeLimitAsync(IBlockIndex blockIndex, int stateSizeLimit)
        {
            if (stateSizeLimit <= 0)
            {
                return;
            }
            await AddBlockExecutedDataAsync(blockIndex, new Int32Value { Value = stateSizeLimit });

            Logger.LogDebug($"State limit size changed to {stateSizeLimit}");
        }
Example #6
0
        public IExecutionObserverThreshold GetExecutionObserverThreshold(IBlockIndex blockIndex)
        {
            var branchCountObserverThreshold = GetBlockExecutedData(blockIndex, BranchCountThresholdKey)?.Value ??
                                               SmartContractConstants.ExecutionBranchThreshold;
            var callCountObserverThreshold = GetBlockExecutedData(blockIndex, CallCountThresholdKey)?.Value ??
                                             SmartContractConstants.ExecutionBranchThreshold;

            return(new ExecutionObserverThreshold
            {
                ExecutionBranchThreshold = branchCountObserverThreshold,
                ExecutionCallThreshold = callCountObserverThreshold
            });
        }
Example #7
0
        public async Task AddBlockExecutedDataAsync(IBlockIndex blockIndex, IDictionary <string, T> blockExecutedData)
        {
            await _blockchainExecutedDataManager.AddBlockExecutedCacheAsync(blockIndex.BlockHash, blockExecutedData.ToDictionary
                                                                                (pair => pair.Key, pair => Serialize(pair.Value)));

            foreach (var pair in blockExecutedData)
            {
                if (blockIndex.BlockHeight > AElfConstants.GenesisBlockHeight &&
                    (!_changeHeight.TryGetValue(pair.Key, out var height) || height < blockIndex.BlockHeight))
                {
                    _changeHeight[pair.Key] = blockIndex.BlockHeight;
                }
                _dictionary.TryRemove(pair.Key, out _);
            }
        }
Example #8
0
        public async Task SetExecutionObserverThresholdAsync(IBlockIndex blockIndex,
                                                             IExecutionObserverThreshold executionObserverThreshold)
        {
            if (!ValidateExecutionObserverThreshold(executionObserverThreshold))
            {
                return;
            }

            await AddBlockExecutedDataAsync(blockIndex, BranchCountThresholdKey,
                                            new Int32Value { Value = executionObserverThreshold.ExecutionBranchThreshold });
            await AddBlockExecutedDataAsync(blockIndex, CallCountThresholdKey,
                                            new Int32Value { Value = executionObserverThreshold.ExecutionCallThreshold });

            Logger.LogDebug(
                $"ExecutionObserverThreshold has been changed. Branch count threshold is {executionObserverThreshold.ExecutionBranchThreshold}. Call count threshold is {executionObserverThreshold.ExecutionCallThreshold}");
        }
        public async Task SetLimitAsync(IBlockIndex blockIndex, int limit)
        {
            if (limit <= _systemTransactionCount)
            {
                return;
            }

            var blockTransactionLimit = new Int32Value
            {
                Value = limit
            };

            await AddBlockExecutedDataAsync(blockIndex, blockTransactionLimit);

            Logger.LogDebug($"BlockTransactionLimit has been changed to {limit}");
        }
Example #10
0
        public T GetBlockExecutedData(IBlockIndex chainContext, string key)
        {
            if (!_changeHeight.TryGetValue(key, out _) && _dictionary.TryGetValue(key, out var value))
            {
                return(value);
            }

            var ret = AsyncHelper.RunSync(() => _blockchainExecutedDataManager.GetExecutedCacheAsync(key,
                                                                                                     chainContext.BlockHeight,
                                                                                                     chainContext.BlockHash));

            var blockExecutedData = Deserialize(ret.Value);

            //if executed is in Store, it will not change when forking
            if (ret.IsInStore && !_changeHeight.TryGetValue(key, out _))
            {
                _dictionary[key] = blockExecutedData;
            }
            return(blockExecutedData);
        }
Example #11
0
 protected T GetBlockExecutedData(IBlockIndex chainContext, string key)
 {
     return(_cachedBlockchainExecutedDataService.GetBlockExecutedData(chainContext, GetBlockExecutedDataKey(key)));
 }
Example #12
0
 public async Task SetTransactionSizeFeeSymbolsAsync(IBlockIndex blockIndex,
                                                     TransactionSizeFeeSymbols transactionSizeFeeSymbols)
 {
     await AddBlockExecutedDataAsync(blockIndex, transactionSizeFeeSymbols);
 }
 public async Task SetTotalTransactionFeesMapAsync(IBlockIndex blockIndex,
                                                   TotalTransactionFeesMap totalTransactionFeesMap)
 {
     await AddBlockExecutedDataAsync(blockIndex, totalTransactionFeesMap);
 }
Example #14
0
 public void AddCodeHashCache(IBlockIndex blockIndex, Address address, Hash codeHash)
 {
     throw new System.NotImplementedException();
 }
Example #15
0
 public virtual async Task SetSmartContractAddressAsync(IBlockIndex blockIndex, string name, Address address)
 {
     await _smartContractAddressProvider.SetSmartContractAddressAsync(blockIndex, name, address);
 }
 public Task AddCalculateFunctions(IBlockIndex blockIndex,
                                   Dictionary <string, CalculateFunction> calculateFunctionDictionary)
 {
     return(Task.CompletedTask);
 }
 public Task SetTransactionPackingOptionAsync(IBlockIndex blockIndex, bool isTransactionPackable)
 {
     _isTransactionPackable = isTransactionPackable;
     return(Task.CompletedTask);
 }
Example #18
0
 protected async Task AddBlockExecutedDataAsync(IBlockIndex blockIndex, T blockExecutedData)
 {
     await _cachedBlockchainExecutedDataService.AddBlockExecutedDataAsync(blockIndex,
                                                                          GetBlockExecutedDataKey(), blockExecutedData);
 }
 public async Task SetTotalResourceTokensMapsAsync(IBlockIndex blockIndex,
                                                   TotalResourceTokensMaps totalResourceTokensMaps)
 {
     await AddBlockExecutedDataAsync(blockIndex, totalResourceTokensMaps);
 }
        public Task <int> GetStateSizeLimitAsync(IBlockIndex blockIndex)
        {
            var stateSizeLimit = GetBlockExecutedData(blockIndex)?.Value ?? SmartContractConstants.StateSizeLimit;

            return(Task.FromResult(stateSizeLimit));
        }
Example #21
0
 public async Task SetTransactionPackingOptionAsync(IBlockIndex blockIndex, bool isTransactionPackable)
 {
     await AddBlockExecutedDataAsync(blockIndex, new BoolValue { Value = isTransactionPackable });
 }
Example #22
0
        /// <summary>
        /// Create a txn with provided data.
        /// </summary>
        /// <param name="from"></param>
        /// <param name="methodName"></param>
        /// <param name="blockIndex"></param>
        /// <param name="bytes"></param>
        /// <returns></returns>
        private async Task <Transaction> GenerateNotSignedTransactionAsync(Address from, string methodName, IBlockIndex blockIndex, ByteString bytes)
        {
            var address = await _smartContractAddressService.GetAddressByContractNameAsync(
                new ChainContext
            {
                BlockHash   = blockIndex.BlockHash,
                BlockHeight = blockIndex.BlockHeight
            }, CrossChainSmartContractAddressNameProvider.StringName);

            return(new Transaction
            {
                From = from,
                To = address,
                RefBlockNumber = blockIndex.BlockHeight,
                RefBlockPrefix = ByteString.CopyFrom(blockIndex.BlockHash.Value.Take(4).ToArray()),
                MethodName = methodName,
                Params = bytes,
            });
        }
 public async Task AddCalculateFunctions(IBlockIndex blockIndex,
                                         Dictionary <string, CalculateFunction> calculateFunctionDictionary)
 {
     await AddBlockExecutedDataAsync(blockIndex, calculateFunctionDictionary);
 }
 public async Task SetTotalResourceTokensMapsAsync(IBlockIndex blockIndex,
                                                   TotalResourceTokensMaps totalResourceTokensMaps)
 {
     Logger.LogDebug($"Add TotalResourceTokensMaps: {totalResourceTokensMaps}");
     await AddBlockExecutedDataAsync(blockIndex, totalResourceTokensMaps);
 }
Example #25
0
 public async Task <ByteString> GetBlockExecutedDataAsync(IBlockIndex chainContext, string key)
 {
     return((await _blockchainExecutedDataManager.GetExecutedCacheAsync(key, chainContext.BlockHeight,
                                                                        chainContext.BlockHash)).Value);
 }
        public Task <int> GetLimitAsync(IBlockIndex blockIndex)
        {
            var limit = GetBlockExecutedData(blockIndex);

            return(Task.FromResult(limit?.Value ?? int.MaxValue));
        }
Example #27
0
 protected T GetBlockExecutedData(IBlockIndex chainContext, IMessage key = null)
 {
     return(_cachedBlockchainExecutedDataService.GetBlockExecutedData(chainContext, GetBlockExecutedDataKey(key)));
 }
Example #28
0
 public async Task SetSmartContractRegistrationAsync(IBlockIndex blockIndex, Address address,
                                                     SmartContractRegistration smartContractRegistration)
 {
     await AddBlockExecutedDataAsync(blockIndex, address, smartContractRegistration);
 }
Example #29
0
 protected async Task AddBlockExecutedDataAsync <TKey>(IBlockIndex blockIndex, IDictionary <TKey, T> blockExecutedData)
     where TKey : IMessage <TKey>
 {
     var dic = blockExecutedData.ToDictionary(pair => GetBlockExecutedDataKey(pair.Key), pair => pair.Value);
     await _cachedBlockchainExecutedDataService.AddBlockExecutedDataAsync(blockIndex, dic);
 }
Example #30
0
 public async Task SetNonparallelContractCodeAsync(IBlockIndex blockIndex,
                                                   IDictionary <Address, NonparallelContractCode> nonparallelContractCodes)
 {
     await AddBlockExecutedDataAsync(blockIndex, nonparallelContractCodes);
 }