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

unique hashes for spc txs #171

Closed
wants to merge 0 commits into from
Closed

unique hashes for spc txs #171

wants to merge 0 commits into from

Conversation

longwinterday
Copy link

No description provided.

@liam-lai
Copy link
Collaborator

liam-lai commented Aug 6, 2022

Hi, can you fetch the latest code from dev-upgrade please? Your test is failed.

@wjrjerome
Copy link
Collaborator

Could you please create relevant unit or integration tests to cover the changes you made?

@wgr523
Copy link
Collaborator

wgr523 commented Aug 7, 2022

I think you use this line time.Now().UnixNano() / int64(time.Millisecond) % txMatchGasLimit to avoid the transaction contains the same gas limit. However, there is still a small chance of 1/txMatchGasLimit such that the gas limit is the same. Have you considered using time.Now().UnixNano() / int64(time.Millisecond)?

@wgr523
Copy link
Collaborator

wgr523 commented Aug 7, 2022

By the way, is it feasible to use incremental nonce, just like normal transactions? If nonce is incremented (nonce+=1), then nonce will be different for each transaction.

@longwinterday
Copy link
Author

I think you use this line time.Now().UnixNano() / int64(time.Millisecond) % txMatchGasLimit to avoid the transaction contains the same gas limit. However, there is still a small chance of 1/txMatchGasLimit such that the gas limit is the same. Have you considered using time.Now().UnixNano() / int64(time.Millisecond)?

No. It is impossible to use Gas Limit larger when pool Gas Limit

// Ensure the transaction doesn't exceed the current block limit gas.

However, if it be based on case that blocks appears every 2 seconds and it looks so, it is possible to use time.Now().UnixNano() / int64(time.Millisecond * 100) % txMatchGasLimit it is about 1/40_000_000 every 46days a chance to have same dynamicTxMatchGasLimit and the nonce should be kept but actually I can't find cases with triple and more not unique transactions. So the chances are about 1 not unique transaction every 105 000 years.

Nonce can be also incremented but it won't guarantee that every block will have special transaction cause of possible errors. Like get address from in that case

from, err := types.Sender(types.MakeSigner(config, header.Number), tx)

@longwinterday
Copy link
Author

Could you please create relevant unit or integration tests to cover the changes you made?

Hmm. I do not see special test cases for these changes. I suppose all current test cover the worker's functional.

miner/worker.go Outdated
@@ -701,7 +701,8 @@ func (self *worker) commitNewWork() {
return
}
nonce := work.state.GetNonce(self.coinbase)
tx := types.NewTransaction(nonce, common.HexToAddress(common.XDCXAddr), big.NewInt(0), txMatchGasLimit, big.NewInt(0), txMatchBytes)
dynamicTxMatchGasLimit := uint64(time.Now().UnixNano() / int64(time.Millisecond) % txMatchGasLimit)
tx := types.NewTransaction(nonce, common.HexToAddress(common.XDCXAddr), big.NewInt(0), dynamicTxMatchGasLimit, big.NewInt(0), txMatchBytes)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you please create a function in types that avoid duplicate code all over the place

@wjrjerome
Copy link
Collaborator

Could you please create relevant unit or integration tests to cover the changes you made?

Hmm. I do not see special test cases for these changes. I suppose all current test cover the worker's functional.

Ideally, it would be best to simulate the issue in unit test prior to your fix. i.e it shall fail.
Then run the test against your fix to verify it will pass.

@wjrjerome wjrjerome requested a review from wgr523 August 23, 2022 12:49
miner/worker.go Outdated
@@ -701,7 +701,8 @@ func (self *worker) commitNewWork() {
return
}
nonce := work.state.GetNonce(self.coinbase)
tx := types.NewTransaction(nonce, common.HexToAddress(common.XDCXAddr), big.NewInt(0), txMatchGasLimit, big.NewInt(0), txMatchBytes)
dynamicTxMatchGasLimit := uint64(time.Now().UnixNano() / int64(time.Millisecond) % txMatchGasLimit)
tx := types.NewTransaction(nonce, common.HexToAddress(common.XDCXAddr), big.NewInt(0), dynamicTxMatchGasLimit, big.NewInt(0), txMatchBytes)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Have you considered creating a new function types.NewTransactionWithDynamicGasLimit where all the randomised logic such as uint64(time.Now().UnixNano() / int64(time.Millisecond) % txMatchGasLimit) can hide inside it.
Then call this function in this file instead of duplicating it across 4 different places?
Also, it would be very straightforward to write a unit test for such function.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@longwinterday could you reply above please

@liam-lai
Copy link
Collaborator

@longwinterday will this change create a hard forking?

@gzliudan
Copy link
Collaborator

gzliudan commented Jul 2, 2024

solved by #430 #501 #521

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.

5 participants