|
|
|
@ -221,12 +221,12 @@ func (node *Node) tryBroadcast(tx *types.Transaction) { |
|
|
|
|
msg := proto_node.ConstructTransactionListMessageAccount(types.Transactions{tx}) |
|
|
|
|
|
|
|
|
|
shardGroupID := nodeconfig.NewGroupIDByShardID(nodeconfig.ShardID(tx.ShardID())) |
|
|
|
|
utils.Logger().Info().Str("shardGroupID", string(shardGroupID)).Msg("tryBroadcast") |
|
|
|
|
utils.Logger().Info().Str("tx_hash", tx.Hash().Hex()).Str("shardGroupID", string(shardGroupID)).Msg("tryBroadcast") |
|
|
|
|
|
|
|
|
|
for attempt := 0; attempt < NumTryBroadCast; attempt++ { |
|
|
|
|
err := node.host.SendMessageToGroups([]nodeconfig.GroupID{shardGroupID}, p2p.ConstructMessage(msg)) |
|
|
|
|
if err != nil { |
|
|
|
|
utils.Logger().Error().Int("attempt", attempt).Msg("Error when trying to broadcast tx") |
|
|
|
|
utils.Logger().Error().Str("tx_hash", tx.Hash().Hex()).Int("attempt", attempt).Msg("Error when trying to broadcast tx") |
|
|
|
|
} else { |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
@ -239,12 +239,12 @@ func (node *Node) tryBroadcastStaking(stakingTx *staking.StakingTransaction) { |
|
|
|
|
shardGroupID := nodeconfig.NewGroupIDByShardID( |
|
|
|
|
nodeconfig.ShardID(shard.BeaconChainShardID), |
|
|
|
|
) // broadcast to beacon chain
|
|
|
|
|
utils.Logger().Info().Str("shardGroupID", string(shardGroupID)).Msg("tryBroadcastStaking") |
|
|
|
|
utils.Logger().Info().Str("tx_hash", stakingTx.Hash().Hex()).Str("shardGroupID", string(shardGroupID)).Msg("tryBroadcastStaking") |
|
|
|
|
|
|
|
|
|
for attempt := 0; attempt < NumTryBroadCast; attempt++ { |
|
|
|
|
if err := node.host.SendMessageToGroups([]nodeconfig.GroupID{shardGroupID}, |
|
|
|
|
p2p.ConstructMessage(msg)); err != nil { |
|
|
|
|
utils.Logger().Error().Int("attempt", attempt).Msg("Error when trying to broadcast staking tx") |
|
|
|
|
utils.Logger().Error().Str("tx_hash", stakingTx.Hash().Hex()).Int("attempt", attempt).Msg("Error when trying to broadcast staking tx") |
|
|
|
|
} else { |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
@ -267,25 +267,40 @@ func addPendingTransactions(registry *registry.Registry, newTxs types.Transactio |
|
|
|
|
if tx.ShardID() != tx.ToShardID() { |
|
|
|
|
if !acceptCx { |
|
|
|
|
errs = append(errs, errors.WithMessage(errInvalidEpoch, "cross-shard tx not accepted yet")) |
|
|
|
|
utils.Logger().Debug().Err(errors.WithMessage(errInvalidEpoch, "cross-shard tx not accepted yet")). |
|
|
|
|
Str("tx_hash", tx.Hash().Hex()). |
|
|
|
|
Msg("[addPendingTransactions] tx is not added to pending pool") |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
if isBeforeHIP30 { |
|
|
|
|
if tx.ToShardID() >= nxtShards { |
|
|
|
|
errs = append(errs, errors.New("shards 2 and 3 are shutting down in the next epoch")) |
|
|
|
|
utils.Logger().Debug().Err(errors.WithMessage(errInvalidEpoch, "shards 2 and 3 are shutting down in the next epoch")). |
|
|
|
|
Str("tx_hash", tx.Hash().Hex()). |
|
|
|
|
Msg("[addPendingTransactions] tx is not added to pending pool") |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if tx.IsEthCompatible() && !bc.Config().IsEthCompatible(bc.CurrentBlock().Epoch()) { |
|
|
|
|
errs = append(errs, errors.WithMessage(errInvalidEpoch, "ethereum tx not accepted yet")) |
|
|
|
|
utils.Logger().Debug().Err(errors.WithMessage(errInvalidEpoch, "ethereum tx not accepted yet")). |
|
|
|
|
Str("tx_hash", tx.Hash().Hex()). |
|
|
|
|
Msg("[addPendingTransactions] tx is not added to pending pool") |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
if isBeforeHIP30 { |
|
|
|
|
if bc.ShardID() >= nxtShards { |
|
|
|
|
errs = append(errs, errors.New("shards 2 and 3 are shutting down in the next epoch")) |
|
|
|
|
utils.Logger().Debug().Err(errors.WithMessage(errInvalidEpoch, "shards 2 and 3 are shutting down in the next epoch")). |
|
|
|
|
Str("tx_hash", tx.Hash().Hex()). |
|
|
|
|
Msg("[addPendingTransactions] tx is not added to pending pool") |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
utils.Logger().Debug(). |
|
|
|
|
Str("tx_hash", tx.Hash().Hex()). |
|
|
|
|
Msg("[addPendingTransactions] tx is added to the txs pool array") |
|
|
|
|
poolTxs = append(poolTxs, tx) |
|
|
|
|
} |
|
|
|
|
errs = append(errs, registry.GetTxPool().AddRemotes(poolTxs)...) |
|
|
|
@ -305,9 +320,19 @@ func (node *Node) addPendingStakingTransactions(newStakingTxs staking.StakingTra |
|
|
|
|
if node.Blockchain().Config().IsPreStaking(node.Blockchain().CurrentHeader().Epoch()) { |
|
|
|
|
poolTxs := types.PoolTransactions{} |
|
|
|
|
for _, tx := range newStakingTxs { |
|
|
|
|
utils.Logger().Debug(). |
|
|
|
|
Str("tx_hash", tx.Hash().Hex()). |
|
|
|
|
Msg("[addPendingStakingTransactions] tx is added to the txs pool array") |
|
|
|
|
poolTxs = append(poolTxs, tx) |
|
|
|
|
} |
|
|
|
|
errs := node.TxPool.AddRemotes(poolTxs) |
|
|
|
|
if len(errs) > 0 { |
|
|
|
|
for _, err := range errs { |
|
|
|
|
utils.Logger().Debug(). |
|
|
|
|
Err(err). |
|
|
|
|
Msg("[addPendingStakingTransactions] AddRemotes failed") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
pendingCount, queueCount := node.TxPool.Stats() |
|
|
|
|
utils.Logger().Info(). |
|
|
|
|
Int("length of newStakingTxs", len(poolTxs)). |
|
|
|
@ -360,7 +385,7 @@ func (node *Node) AddPendingTransaction(newTx *types.Transaction) error { |
|
|
|
|
var err error |
|
|
|
|
for i := range errs { |
|
|
|
|
if errs[i] != nil { |
|
|
|
|
utils.Logger().Info().Err(errs[i]).Msg("[AddPendingTransaction] Failed adding new transaction") |
|
|
|
|
// utils.Logger().Info().Err(errs[i]).Msg("[AddPendingTransaction] Failed adding new transaction")
|
|
|
|
|
err = errs[i] |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|