Exemplo n.º 1
0
 private void OnNewHeadBlock(object?sender, BlockEventArgs e)
 {
     if (e.Block is not null)
     {
         TryPublishReceiptsInBackground(e.Block.Header, () => _receiptStorage.Get(e.Block), nameof(_blockTree.NewHeadBlock));
     }
 }
Exemplo n.º 2
0
        private void OnNewHeadBlock(object sender, BlockEventArgs blockEventArgs)
        {
            Block block = blockEventArgs.Block;

            if (_blockTree.BestKnownNumber > block.Number)
            {
                return;
            }

            int counter = 0;

            foreach (PeerInfo peerInfo in _pool.AllPeers)
            {
                if (peerInfo.TotalDifficulty < (block.TotalDifficulty ?? UInt256.Zero))
                {
                    peerInfo.SyncPeer.SendNewBlock(block);
                    counter++;
                }
            }

            if (counter > 0)
            {
                if (_logger.IsDebug)
                {
                    _logger.Debug($"Broadcasting block {block.ToString(Block.Format.Short)} to {counter} peers.");
                }
            }
        }
Exemplo n.º 3
0
        private void OnNewHeadBlock(object?sender, BlockEventArgs e)
        {
            long toPrune = e.Block.Number - _followDistance;

            if (toPrune > 0)
            {
                var level = _blockTree.FindLevel(toPrune);
                if (level != null)
                {
                    if (_logger.IsTrace)
                    {
                        _logger.Trace($"Pruning witness from blocks with number {toPrune}");
                    }

                    for (int i = 0; i < level.BlockInfos.Length; i++)
                    {
                        var blockInfo = level.BlockInfos[i];
                        if (blockInfo.BlockHash != null)
                        {
                            _witnessRepository.Delete(blockInfo.BlockHash);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
 void HandleBlockPlaced(object sender, BlockEventArgs e)
 {
     e.Manager.Faded   += HandleBlockFaded;
     e.Manager.Fading  += HandleBlockFading;
     e.Manager.Dropped += HandleBlockDropped;
     State              = TowerState.REMOVING;
 }
Exemplo n.º 5
0
        private void BlockTreeOnNewHeadBlock(object?sender, BlockEventArgs e)
        {
            Block?block = e.Block;

            if (!_connected)
            {
                return;
            }

            long timestamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();

            if (timestamp - _lastBlockProcessedTimestamp < ThrottlingThreshold)
            {
                return;
            }

            if (block == null)
            {
                _logger.Error($"{nameof(EthStatsIntegration)} received null as the new head block.");
                return;
            }

            if (_logger.IsDebug)
            {
                _logger.Debug("ETH Stats sending 'block', 'pending' messages...");
            }
            _lastBlockProcessedTimestamp = timestamp;
            SendBlockAsync(block);
            SendPendingAsync(_txPool.GetPendingTransactionsCount());
        }
Exemplo n.º 6
0
 void HandleBlockDropped(object sender, BlockEventArgs e) // game over
 {
     if (!e.transform.parent.name.Contains("Row #1"))
     {
         State = TowerState.FALLING;
     }
 }
Exemplo n.º 7
0
        private void DisplayBlock(object sender, BlockEventArgs e)
        {
            var walletStore = WalletStore.Instance();
            var flyout      = new BlockFlyoutPage(e.Data, walletStore.GetAuthenticatedWallet().Network);

            MainWindowStore.Instance().DisplayFlyout(flyout, Position.Right, 400);
        }
Exemplo n.º 8
0
        private void PeerNetwork_LatestBlockReceived(object sender, BlockEventArgs e)
        {
            IBlockDefinition lastReceivedBlock = null;
            IBlockDefinition lastLocalBlock    = OnGetLatestBlock();

            if (e.Block == null)
            {
                return;
            }
            else
            {
                lastReceivedBlock = e.Block;
            }

            if (lastReceivedBlock.Index > lastLocalBlock.Index)
            {
                if (lastReceivedBlock.PreviousHash == lastLocalBlock.Hash)
                {
                    OnAddBlockToChain(lastReceivedBlock);
                }
                else
                {
                    // received a Block with higher index and the previous hash dosent match the current hash from local => our local chain is out of date
                    peerNetwork.FullBlockchainRequest(Chain);
                }
            }
            else
            {
                // our local blockchain is longer then the received
                // longer blockchain wins we do nothing
            }
        }
Exemplo n.º 9
0
        private void DrawChangedBlocks(BlockEventArgs e)
        {
            using (var graphics = Graphics.FromImage(gameDeckBitmap))
            {
                foreach (var block in e.Blocks.Where(s => s.Y >= 0))
                {
                    DrawSingleBlock(graphics, block.X, block.Y, GetColor(block.Status, hiddenColor), block.Status != BlockStatus.Hidden ? borderColor : hiddenColor);
                    deck[block.X, block.Y] = block.Status != BlockStatus.Hidden;
                }
            }
            gameDeckPicBox.Refresh();

            if (e.Blocks.All(s => s.Y >= 0))
            {
                return;
            }

            using (var graphics = Graphics.FromImage(headerBitmap))
            {
                foreach (var block in e.Blocks.Where(s => s.Y < 0))
                {
                    DrawSingleBlock(graphics, block.X, tetrominoWidthHeightBlocks + block.Y, GetColor(block.Status, BackColor), block.Status != BlockStatus.Hidden ? borderColor : BackColor);
                }
            }
            headerPicBox.Refresh();
        }
Exemplo n.º 10
0
 private void OnNewHeadBlock(object sender, BlockEventArgs e)
 {
     if (_newBlockLock.CurrentCount == 0)
     {
         _newBlockLock.Release();
     }
 }
Exemplo n.º 11
0
 private void BlockTreeOnNewBestSuggestedBlock(object sender, BlockEventArgs e)
 {
     lock (_syncToken)
     {
         _cancellationTokenSource?.Cancel();
     }
 }
Exemplo n.º 12
0
        public void NewHeadSubscription_on_NewHeadBlock_event_with_null_block()
        {
            BlockEventArgs blockEventArgs = new BlockEventArgs(null);

            JsonRpcResult jsonRpcResult = GetNewHeadBlockResult(blockEventArgs, out _);

            jsonRpcResult.Response.Should().BeNull();
        }
Exemplo n.º 13
0
        public override bool Equals(object obj)
        {
            BlockEventArgs args = obj as BlockEventArgs;

            return((args == null) ? false : this.piece.Equals(args.piece) &&
                   this.id.Equals(args.id) &&
                   this.block.Equals(args.block));
        }
 private void OnBlockProduced(object?sender, BlockEventArgs e)
 {
     // PostMerge blocks are suggested in Engine API
     if (!e.Block.IsPostMerge)
     {
         _blockTree.SuggestBlock(e.Block);
     }
 }
 private void docTypeBlock_Selected(object source, BlockEventArgs e)
 {
     typeNameEnable = docTypeBlock.ID > 0 && Environment.DoesDocTypeNameExist(docTypeBlock.ID);
     UpdateControls();
     if (!typeNameEnable)
     {
         textBoxName.Text = "";
     }
 }
        private void OnTextSpansChanged(
            object sender,
            BlockEventArgs e)
        {
            int blockIndex = blocks.IndexOf(e.Block);
            var args       = new LineChangedArgs(blockIndex);

            RaiseLineChanged(args);
        }
        /// <summary>
        /// Raises an event that a block's text spans had changed.
        /// </summary>
        /// <param name="block"></param>
        public void RaiseTextSpansChanged(Block block)
        {
            EventHandler <BlockEventArgs> listeners = TextSpansChanged;

            if (listeners != null)
            {
                var args = new BlockEventArgs(block);
                listeners(this, args);
            }
        }
Exemplo n.º 18
0
        protected virtual void RaiseSelectedBlockChangedEvent()
        {
            BlockEventArgs e = new BlockEventArgs();

            // Get selected block based on view mode
            int selectedBlock = -1;

            switch (viewMode)
            {
            case ViewModes.Exterior:
                selectedBlock = selectedExteriorBlock;
                break;

            case ViewModes.Dungeon:
                selectedBlock = selectedDungeonBlock;
                break;
            }

            if (selectedBlock == -1)
            {
                // Dummy args
                e.X         = -1;
                e.Y         = -1;
                e.Name      = string.Empty;
                e.ViewMode  = viewMode;
                e.BlockType = DFBlock.BlockTypes.Unknown;
                e.RdbType   = DFBlock.RdbTypes.Unknown;
            }
            else
            {
                // Populate args
                e.ViewMode = viewMode;
                switch (viewMode)
                {
                case ViewModes.Exterior:
                    e.X         = exteriorLayout[mouseOverBlock].x;
                    e.Y         = exteriorLayout[mouseOverBlock].y;
                    e.Name      = exteriorLayout[mouseOverBlock].name;
                    e.BlockType = DFBlock.BlockTypes.Rmb;
                    e.RdbType   = DFBlock.RdbTypes.Unknown;
                    break;

                case ViewModes.Dungeon:
                    e.X         = dungeonLayout[mouseOverBlock].x;
                    e.Y         = dungeonLayout[mouseOverBlock].y;
                    e.Name      = dungeonLayout[mouseOverBlock].name;
                    e.BlockType = DFBlock.BlockTypes.Rdb;
                    e.RdbType   = dungeonLayout[mouseOverBlock].rdbType;
                    break;
                }
            }

            // Raise event
            SelectedBlockChanged(this, e);
        }
Exemplo n.º 19
0
        private void OnNewBestBlock(object sender, BlockEventArgs blockEventArgs)
        {
            ProcessingOptions options = ProcessingOptions.None;

            if (_options.StoreReceiptsByDefault)
            {
                options |= ProcessingOptions.StoreReceipts;
            }

            Enqueue(blockEventArgs.Block, options);
        }
Exemplo n.º 20
0
        private void OnConditionsChange(object?sender, BlockEventArgs e)
        {
            Task.Run(() =>
            {
                bool isSyncing = CheckSyncing();

                if (isSyncing == IsSyncing)
                {
                    if (_logger.IsTrace)
                    {
                        _logger.Trace($"Syncing subscription {Id} didn't changed syncing status: {IsSyncing}");
                    }
                    return;
                }

                if (_logger.IsTrace)
                {
                    _logger.Trace($"Syncing subscription {Id} changed syncing status from {IsSyncing} to {isSyncing}");
                }

                IsSyncing = isSyncing;
                JsonRpcResult result;

                if (isSyncing == false)
                {
                    result = CreateSubscriptionMessage(isSyncing);
                }
                else
                {
                    result = CreateSubscriptionMessage(new SyncingResult
                    {
                        IsSyncing     = isSyncing,
                        CurrentBlock  = _blockTree.Head.Number,
                        HighestBlock  = BestSuggestedNumber,
                        StartingBlock = 0L
                    });
                }


                JsonRpcDuplexClient.SendJsonRpcResult(result);
                _logger.Trace($"Syncing subscription {Id} printed SyncingResult object.");
            }).ContinueWith(
                t =>
                t.Exception?.Handle(ex =>
            {
                if (_logger.IsDebug)
                {
                    _logger.Debug($"Syncing subscription {Id}: Failed Task.Run.");
                }
                return(true);
            })
                , TaskContinuationOptions.OnlyOnFaulted
                );
        }
Exemplo n.º 21
0
        private void OnNewHeadBlock(object?sender, BlockEventArgs blockEventArgs)
        {
            Task.Run(() =>
            {
                Block block = blockEventArgs.Block;
                if (_blockTree.BestKnownNumber > block.Number)
                {
                    return;
                }

                int peerCount         = _pool.PeerCount;
                double broadcastRatio = Math.Sqrt(peerCount) / peerCount;

                int counter = 0;
                foreach (PeerInfo peerInfo in _pool.AllPeers)
                {
                    if (peerInfo.TotalDifficulty < (block.TotalDifficulty ?? UInt256.Zero))
                    {
                        if (_broadcastRandomizer.NextDouble() < broadcastRatio)
                        {
                            peerInfo.SyncPeer.NotifyOfNewBlock(block, SendBlockPriority.High);
                            counter++;
                        }
                        else
                        {
                            peerInfo.SyncPeer.NotifyOfNewBlock(block, SendBlockPriority.Low);
                        }
                    }
                }

                if (counter > 0)
                {
                    if (_logger.IsDebug)
                    {
                        _logger.Debug(
                            $"Broadcasting block {block.ToString(Block.Format.Short)} to {counter} peers.");
                    }
                }

                if ((block.Number - Sync.MaxReorgLength) % CanonicalHashTrie.SectionSize == 0)
                {
                    _ = BuildCHT();
                }
            }).ContinueWith(
                t =>
                t.Exception?.Handle(ex =>
            {
                _logger.Error(ex.Message, ex);
                return(true);
            })
                , TaskContinuationOptions.OnlyOnFaulted
                );
        }
Exemplo n.º 22
0
 private void BlockTreeOnNewHeadBlock(object sender, BlockEventArgs e)
 {
     if (_dbBatchProcessed != null)
     {
         if (e.Block.Number == _currentDbLoadBatchEnd)
         {
             TaskCompletionSource completionSource = _dbBatchProcessed;
             _dbBatchProcessed = null;
             completionSource.SetResult();
         }
     }
 }
Exemplo n.º 23
0
        private void BlockTreeOnNewHeadBlock(object sender, BlockEventArgs e)
        {
            long number = e.Block.Number;

            for (int i = 64; i > 0; i--)
            {
                if (_tokens.TryGetValue(number - i, out CancellationTokenSource token))
                {
                    token.Cancel();
                }
            }
        }
        /// <summary>
        /// Raises an event that a block's type had changed.
        /// </summary>
        /// <param name="block"></param>
        /// <param name="oldBlockType"></param>
        public void RaiseBlockTypeChanged(
            Block block,
            BlockType oldBlockType)
        {
            EventHandler <BlockEventArgs> listeners = BlockTypeChanged;

            if (listeners != null)
            {
                var args = new BlockEventArgs(block);
                listeners(this, args);
            }
        }
Exemplo n.º 25
0
 private void DrawHoldTetromino(BlockEventArgs e)
 {
     using (var graphics = Graphics.FromImage(holdTetrominoBitmap))
     {
         graphics.Clear(BackColor);
         foreach (var block in e.Blocks)
         {
             DrawSingleBlock(graphics, block.X, block.Y, GetColor(block.Status, BackColor), block.Status != BlockStatus.Hidden ? borderColor : hiddenColor);
         }
     }
     holdTetrominoPicBox.Refresh();
 }
Exemplo n.º 26
0
        private void OnNewBlock(object sender, BlockEventArgs e)
        {
            BeamProcess(e.Block);
            long number = e.Block.Number;

            for (int i = 64; i > 6; i--)
            {
                if (_tokens.TryGetValue(number - i, out CancellationTokenSource token))
                {
                    token.Cancel();
                }
            }
        }
Exemplo n.º 27
0
        public void SyncingSubscription_on_NewHeadBlock_event_when_sync_no_change()
        {
            SyncingSubscription syncingSubscription = GetSyncingSubscription(10042, 10024);

            Block          blockChanged   = Build.A.Block.WithNumber(10030).TestObject;
            BlockEventArgs blockEventArgs = new BlockEventArgs(blockChanged);

            _blockTree.Head.Returns(blockChanged);

            JsonRpcResult jsonRpcResult = GetSyncingSubscriptionResult(true, syncingSubscription, blockEventArgs);

            jsonRpcResult.Response.Should().BeNull();
        }
Exemplo n.º 28
0
    void HandleBlockPlaced(object sender, BlockEventArgs e)
    {
        if (BlockPlaced != null)
            BlockPlaced(this, e);
        count--;

        if (count == 0)
        {
            if (Destroyed != null)
                Destroyed(this, new EventArgs());
            Destroy(GetComponent<TopBlockPlacer>());
        }
    }
Exemplo n.º 29
0
        public void NewHeadSubscription_on_NewHeadBlock_event()
        {
            Block          block          = Build.A.Block.WithDifficulty(1991).WithExtraData(new byte[] { 3, 5, 8 }).TestObject;
            BlockEventArgs blockEventArgs = new BlockEventArgs(block);

            JsonRpcResult jsonRpcResult = GetNewHeadBlockResult(blockEventArgs, out var subscriptionId);

            jsonRpcResult.Response.Should().NotBeNull();
            string serialized     = _jsonSerializer.Serialize(jsonRpcResult.Response);
            var    expectedResult = string.Concat("{\"jsonrpc\":\"2.0\",\"method\":\"eth_subscription\",\"params\":{\"subscription\":\"", subscriptionId, "\",\"result\":{\"author\":\"0x0000000000000000000000000000000000000000\",\"difficulty\":\"0x7c7\",\"extraData\":\"0x030508\",\"gasLimit\":\"0x3d0900\",\"gasUsed\":\"0x0\",\"hash\":\"0x2e3c1c2a507dc3071a16300858d4e75390e5f43561515481719a1e0dadf22585\",\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"miner\":\"0x0000000000000000000000000000000000000000\",\"mixHash\":\"0x2ba5557a4c62a513c7e56d1bf13373e0da6bec016755483e91589fe1c6d212e2\",\"nonce\":\"0x00000000000003e8\",\"number\":\"0x0\",\"parentHash\":\"0xff483e972a04a9a62bb4b7d04ae403c615604e4090521ecc5bb7af67f71be09c\",\"receiptsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"sha3Uncles\":\"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347\",\"size\":\"0x200\",\"stateRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"totalDifficulty\":\"0x0\",\"timestamp\":\"0xf4240\",\"transactions\":[],\"transactionsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"uncles\":[]}}}");

            expectedResult.Should().Be(serialized);
        }
Exemplo n.º 30
0
 private void TetrisGame_RowVanish(object sender, BlockEventArgs e)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new Action(() =>
         {
             DrawVanishRows(e);
         }));
     }
     else
     {
         DrawVanishRows(e);
     }
 }
Exemplo n.º 31
0
 private void TetrisGame_HoldTetromino(object sender, BlockEventArgs e)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new Action(() =>
         {
             DrawHoldTetromino(e);
         }));
     }
     else
     {
         DrawHoldTetromino(e);
     }
 }
Exemplo n.º 32
0
 void HandleBlockPlaced(object sender, BlockEventArgs e)
 {
     e.Manager.Faded += HandleBlockFaded;
     e.Manager.Fading += HandleBlockFading;
     e.Manager.Dropped += HandleBlockDropped;
     State = TowerState.REMOVING;
 }
Exemplo n.º 33
0
 void HandleBlockFading(object sender, BlockEventArgs e)
 {
     ToggleBlocksLock(true);
     e.Manager.enabled = true;
 }
Exemplo n.º 34
0
 void HandleBlockFaded(object sender, BlockEventArgs e)
 {
     State = TowerState.PLACING;
 }
Exemplo n.º 35
0
 // game over
 void HandleBlockDropped(object sender, BlockEventArgs e)
 {
     if (!e.transform.parent.name.Contains("Row #1"))
         State = TowerState.FALLING;
 }