Esempio n. 1
0
        public void AddPeer(IUserOperationPoolPeer peer)
        {
            PeerInfo peerInfo = new(peer);

            if (_broadcaster.AddPeer(peerInfo))
            {
                // TODO: Gather all ops for all pools and submit at the same time
                Address[]         entryPoints    = new Address[_userOperationPools.Count];
                UserOperation[][] userOperations = new UserOperation[_userOperationPools.Count][];
                int counter     = 0;
                int totalLength = 0;
                foreach (KeyValuePair <Address, IUserOperationPool> kv in _userOperationPools)
                {
                    entryPoints[counter]    = kv.Key;
                    userOperations[counter] = kv.Value.GetUserOperations().ToArray();
                    totalLength             = totalLength + userOperations[counter].Length;
                    counter++;
                }
                UserOperationWithEntryPoint[] userOperationsWithEntryPoints = new UserOperationWithEntryPoint[totalLength];
                counter = 0;
                for (int i = 0; i < _userOperationPools.Count; i++)
                {
                    // TODO: Try not to loop here, also maybe this doesn't need to be an array
                    // UserOperation[] userOperations = kv.Value.GetUserOperations().ToArray();
                    // UserOperationWithEntryPoint[] userOperationsWithEntryPoints = new UserOperationWithEntryPoint[userOperations.Length];
                    for (int j = 0; j < userOperations[i].Length; j++)
                    {
                        userOperationsWithEntryPoints[counter] = new UserOperationWithEntryPoint(userOperations[i][j], entryPoints[i]);
                        counter++;
                    }
                }
                _broadcaster.BroadcastOnce(peerInfo, userOperationsWithEntryPoints);

                if (_logger.IsTrace)
                {
                    _logger.Trace($"Added a peer to User Operation pool: {peer.Id}");
                }
            }
        }
Esempio n. 2
0
        private void Handle(UserOperationsMessage uopMsg)
        {
            IList <UserOperationWithEntryPoint> userOperations = uopMsg.UserOperationsWithEntryPoint;

            for (int i = 0; i < userOperations.Count; i++)
            {
                UserOperationWithEntryPoint uop = userOperations[i];
                if (_userOperationPools.TryGetValue(uop.EntryPoint, out IUserOperationPool? pool))
                {
                    ResultWrapper <Keccak> result = pool.AddUserOperation(uop.UserOperation);
                    if (Logger.IsTrace)
                    {
                        Logger.Trace($"{_session.Node:c} sent {uop.UserOperation.Hash} uop to pool for entryPoint {uop.EntryPoint} and it was {result}");
                    }
                }
                else
                {
                    if (Logger.IsTrace)
                    {
                        Logger.Trace($"{_session.Node:c} could not sent {uop.UserOperation.Hash} uop to pool for entryPoint {uop.EntryPoint}, pool does not support the entryPoint");
                    }
                }
            }
        }
Esempio n. 3
0
 public void SendNewUserOperation(UserOperationWithEntryPoint uop)
 {
     SendMessage(new[] { uop });
 }