/**
         * Spawns the child task. This method creates a new SafeContext, and spawns
         * the child task using this SafeContext. The input context of the
         * SafeContext is that of this ExecutionSafeContextManager task.
         *
         * @see jbt.execution.core.ExecutionTask#internalSpawn()
         */

        protected override void InternalSpawn()
        {
            var newContext = new SafeContext(Context);

            child = ((ModelDecorator)ModelTask).getChild().CreateExecutor(
                Executor, this);
            child.AddTaskListener(this);
            child.Spawn(newContext);
        }
예제 #2
0
        private SafeContext PrepareDownloader(DbContext dbContext, ISyncPeer syncPeer)
        {
            SafeContext ctx = new SafeContext();

            ctx = new SafeContext();
            BlockTree blockTree = Build.A.BlockTree().OfChainLength((int)BlockTree.BestSuggestedHeader.Number).TestObject;

            ctx.Pool = new SyncPeerPool(blockTree, new NodeStatsManager(new StatsConfig(), LimboLogs.Instance), 25, LimboLogs.Instance);
            ctx.Pool.Start();
            ctx.Pool.AddPeer(syncPeer);

            SyncConfig syncConfig = new SyncConfig();

            syncConfig.FastSync     = true;
            ctx.SyncModeSelector    = StaticSelector.StateNodesWithFastBlocks;
            ctx.Feed                = new StateSyncFeed(dbContext.LocalCodeDb, dbContext.LocalStateDb, new MemDb(), ctx.SyncModeSelector, blockTree, _logManager);
            ctx.StateSyncDispatcher =
                new StateSyncDispatcher(ctx.Feed, ctx.Pool, new StateSyncAllocationStrategyFactory(), _logManager);
            ctx.StateSyncDispatcher.Start(CancellationToken.None);
            return(ctx);
        }
예제 #3
0
        public async Task HealTreeWithoutBoundaryProofs()
        {
            DbContext dbContext = new DbContext(_logger, _logManager);

            TestItem.Tree.FillStateTreeWithTestAccounts(dbContext.RemoteStateTree);

            Keccak rootHash = dbContext.RemoteStateTree.RootHash;

            ProcessAccountRange(dbContext.RemoteStateTree, dbContext.LocalStateTree, 1, rootHash, TestItem.Tree.AccountsWithPaths);

            SyncPeerMock mock = new SyncPeerMock(dbContext.RemoteStateDb, dbContext.RemoteCodeDb);

            SafeContext ctx = PrepareDownloader(dbContext, mock);

            await ActivateAndWait(ctx, dbContext, 1024);

            DetailedProgress data = ctx.TreeFeed.GetDetailedProgress();


            dbContext.CompareTrees("END");
            Assert.AreEqual(dbContext.RemoteStateTree.RootHash, dbContext.LocalStateTree.RootHash);
            Assert.AreEqual(0, data.RequestedNodesCount);   // 4 boundary proof nodes stitched together => 0
        }
예제 #4
0
        public async Task HealBigSquezedRandomTree()
        {
            DbContext dbContext = new DbContext(_logger, _logManager);

            int pathPoolCount = 100_000;

            Keccak[] pathPool = new Keccak[pathPoolCount];
            SortedDictionary <Keccak, Account> accounts = new();
            int updatesCount   = 0;
            int deletionsCount = 0;

            for (int i = 0; i < pathPoolCount; i++)
            {
                byte[] key = new byte[32];
                ((UInt256)i).ToBigEndian(key);
                Keccak keccak = new Keccak(key);
                pathPool[i] = keccak;
            }

            // generate Remote Tree
            for (int accountIndex = 0; accountIndex < 10000; accountIndex++)
            {
                Account account = TestItem.GenerateRandomAccount();
                Keccak  path    = pathPool[TestItem.Random.Next(pathPool.Length - 1)];

                dbContext.RemoteStateTree.Set(path, account);
                accounts[path] = account;
            }

            dbContext.RemoteStateTree.Commit(0);

            int startingHashIndex = 0;
            int endHashIndex      = 0;
            int blockJumps        = 5;

            for (int blockNumber = 1; blockNumber <= blockJumps; blockNumber++)
            {
                for (int i = 0; i < 19; i++)
                {
                    endHashIndex = startingHashIndex + 1000;

                    ProcessAccountRange(dbContext.RemoteStateTree, dbContext.LocalStateTree, blockNumber, dbContext.RemoteStateTree.RootHash,
                                        accounts.Where(a => a.Key >= pathPool[startingHashIndex] && a.Key <= pathPool[endHashIndex]).Select(a => new PathWithAccount(a.Key, a.Value)).ToArray());

                    startingHashIndex = endHashIndex + 1;
                }

                for (int accountIndex = 0; accountIndex < 1000; accountIndex++)
                {
                    Account account = TestItem.GenerateRandomAccount();
                    Keccak  path    = pathPool[TestItem.Random.Next(pathPool.Length - 1)];

                    if (accounts.ContainsKey(path))
                    {
                        if (TestItem.Random.NextSingle() > 0.5)
                        {
                            dbContext.RemoteStateTree.Set(path, account);
                            accounts[path] = account;
                            updatesCount++;
                        }
                        else
                        {
                            dbContext.RemoteStateTree.Set(path, null);
                            accounts.Remove(path);
                            deletionsCount++;
                        }
                    }
                    else
                    {
                        dbContext.RemoteStateTree.Set(path, account);
                        accounts[path] = account;
                    }
                }

                dbContext.RemoteStateTree.Commit(blockNumber);
            }

            endHashIndex = startingHashIndex + 1000;
            while (endHashIndex < pathPool.Length - 1)
            {
                endHashIndex = startingHashIndex + 1000;
                if (endHashIndex > pathPool.Length - 1)
                {
                    endHashIndex = pathPool.Length - 1;
                }

                ProcessAccountRange(dbContext.RemoteStateTree, dbContext.LocalStateTree, blockJumps, dbContext.RemoteStateTree.RootHash,
                                    accounts.Where(a => a.Key >= pathPool[startingHashIndex] && a.Key <= pathPool[endHashIndex]).Select(a => new PathWithAccount(a.Key, a.Value)).ToArray());


                startingHashIndex += 1000;
            }

            SyncPeerMock mock = new SyncPeerMock(dbContext.RemoteStateDb, dbContext.RemoteCodeDb);

            dbContext.LocalStateTree.RootHash = dbContext.RemoteStateTree.RootHash;
            SafeContext ctx = PrepareDownloader(dbContext, mock);

            await ActivateAndWait(ctx, dbContext, 9);

            DetailedProgress data = ctx.TreeFeed.GetDetailedProgress();

            dbContext.LocalStateTree.UpdateRootHash();
            dbContext.CompareTrees("END");
            _logger.Info($"REQUESTED NODES TO HEAL: {data.RequestedNodesCount}");
            Assert.IsTrue(data.RequestedNodesCount < accounts.Count / 2);
        }
예제 #5
0
 public UserRepository(SafeContext context)
     : base(context)
 {
 }
예제 #6
0
 public Repository(SafeContext context)
 {
     Db    = context;
     DbSet = Db.Set <TEntity>();
 }
예제 #7
0
 public UnitOfWork(SafeContext context)
 {
     _context = context;
 }