Skip to content
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

Merged
merged 1 commit into from
Feb 26, 2020
Merged

only broadcast valid transactions #2308

merged 1 commit into from
Feb 26, 2020

Conversation

rlan35
Copy link
Contributor

@rlan35 rlan35 commented Feb 26, 2020

Previously we blindly re-broadcast all received txns from RPC no matter it's valid or spammer txns. This pr correct that to only rebroadcast the txn if the current node think it's valid (not being a aid to spammers)

Tested locally, it shielded the spamming effect from other nodes.

@LeoHChen LeoHChen merged commit 5681bd0 into harmony-one:master Feb 26, 2020
@LeoHChen
Copy link
Contributor

@rlan35 , Please cherry-pick this change to s3 as well.

}

// 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 {
Copy link
Contributor

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?

Copy link
Contributor

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.

errs := node.addPendingStakingTransactions(staking.StakingTransactions{newStakingTx})
for i := range errs {
if errs[i] != nil {
return
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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.
Better to use if errs[0] != nil { return }

}

// 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto Better to use if errs[0] != nil { return }

return
}
}
utils.Logger().Info().Str("Hash", newTx.Hash().Hex()).Msg("Broadcasting Tx")
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

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).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add err txns counts for log print

@denniswon
Copy link
Contributor

@rlan35 good catch. My comments are all nits. No need to update as a followup. can just take care of them on other related commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants