-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
only broadcast valid transactions #2308
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -278,56 +278,69 @@ func (node *Node) tryBroadcastStaking(stakingTx *staking.StakingTransaction) { | |
} | ||
|
||
// Add new transactions to the pending transaction list. | ||
func (node *Node) addPendingTransactions(newTxs types.Transactions) { | ||
func (node *Node) addPendingTransactions(newTxs types.Transactions) []error { | ||
poolTxs := types.PoolTransactions{} | ||
for _, tx := range newTxs { | ||
poolTxs = append(poolTxs, tx) | ||
} | ||
node.TxPool.AddRemotes(poolTxs) | ||
errs := node.TxPool.AddRemotes(poolTxs) | ||
|
||
pendingCount, queueCount := node.TxPool.Stats() | ||
utils.Logger().Info(). | ||
Int("length of newTxs", len(newTxs)). | ||
Int("totalPending", pendingCount). | ||
Int("totalQueued", queueCount). | ||
Msg("Got more transactions") | ||
return errs | ||
} | ||
|
||
// Add new staking transactions to the pending staking transaction list. | ||
func (node *Node) addPendingStakingTransactions(newStakingTxs staking.StakingTransactions) { | ||
func (node *Node) addPendingStakingTransactions(newStakingTxs staking.StakingTransactions) []error { | ||
if node.NodeConfig.ShardID == shard.BeaconChainShardID && | ||
node.Blockchain().Config().IsPreStaking(node.Blockchain().CurrentHeader().Epoch()) { | ||
poolTxs := types.PoolTransactions{} | ||
for _, tx := range newStakingTxs { | ||
poolTxs = append(poolTxs, tx) | ||
} | ||
node.TxPool.AddRemotes(poolTxs) | ||
errs := node.TxPool.AddRemotes(poolTxs) | ||
pendingCount, queueCount := node.TxPool.Stats() | ||
utils.Logger().Info(). | ||
Int("length of newStakingTxs", len(poolTxs)). | ||
Int("totalPending", pendingCount). | ||
Int("totalQueued", queueCount). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add err txns counts for log print |
||
Msg("Got more staking transactions") | ||
return errs | ||
} | ||
return make([]error, len(newStakingTxs)) | ||
} | ||
|
||
// AddPendingStakingTransaction staking transactions | ||
func (node *Node) AddPendingStakingTransaction(newStakingTx *staking.StakingTransaction) { | ||
if node.NodeConfig.ShardID == shard.BeaconChainShardID { | ||
node.addPendingStakingTransactions(staking.StakingTransactions{newStakingTx}) | ||
errs := node.addPendingStakingTransactions(staking.StakingTransactions{newStakingTx}) | ||
for i := range errs { | ||
if errs[i] != nil { | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if there is at least one error, we don't broadcast any txns? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah nevermind. was confused because was a slice of errors, but its just one transaction. |
||
} | ||
} | ||
utils.Logger().Info().Str("Hash", newStakingTx.Hash().Hex()).Msg("Broadcasting Staking Tx") | ||
node.tryBroadcastStaking(newStakingTx) | ||
} | ||
utils.Logger().Info().Str("Hash", newStakingTx.Hash().Hex()).Msg("Broadcasting Staking Tx") | ||
node.tryBroadcastStaking(newStakingTx) | ||
} | ||
|
||
// AddPendingTransaction adds one new transaction to the pending transaction list. | ||
// This is only called from SDK. | ||
func (node *Node) AddPendingTransaction(newTx *types.Transaction) { | ||
if newTx.ShardID() == node.NodeConfig.ShardID { | ||
node.addPendingTransactions(types.Transactions{newTx}) | ||
errs := node.addPendingTransactions(types.Transactions{newTx}) | ||
for i := range errs { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto Better to use if errs[0] != nil { return } |
||
if errs[i] != nil { | ||
return | ||
} | ||
} | ||
utils.Logger().Info().Str("Hash", newTx.Hash().Hex()).Msg("Broadcasting Tx") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should put this log line above before early error return so that log also prints for error case. |
||
node.tryBroadcast(newTx) | ||
} | ||
utils.Logger().Info().Str("Hash", newTx.Hash().Hex()).Msg("Broadcasting Tx") | ||
node.tryBroadcast(newTx) | ||
} | ||
|
||
// AddPendingReceipts adds one receipt message to pending list. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why aren't we not broadcasting txns here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well I guess addPendingStakingTransactions() is only used from addPendingStakingTransaction, so no need. nvm. checked the code.