-
Notifications
You must be signed in to change notification settings - Fork 179
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
Allow for out of order nonce #2710
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
521f4c2
(WIP) test/e2e: Add parallel segment push test for B
yondonfu 89b86b6
Use sorted hash map for nonce accounting
cyberj0g d3a7d7d
Address review comments - no need for sorted hash map
cyberj0g 1f3f313
go mod tidy
cyberj0g d5a364f
go fmt
cyberj0g fc436be
address review comments
cyberj0g c6237ae
address review comments
cyberj0g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -21,6 +21,9 @@ var errInsufficientSenderReserve = errors.New("insufficient sender reserve") | |||||
// maxWinProb = 2^256 - 1 | ||||||
var maxWinProb = new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(1)) | ||||||
|
||||||
// max number of sender nonces for a given recipient random hash | ||||||
var maxSenderNonces = 50 | ||||||
|
||||||
var paramsExpirationBlock = big.NewInt(10) | ||||||
var paramsExpiryBuffer = int64(1) | ||||||
|
||||||
|
@@ -86,7 +89,7 @@ type recipient struct { | |||||
maxfacevalue *big.Int | ||||||
|
||||||
senderNonces map[string]*struct { | ||||||
nonce uint32 | ||||||
nonceSeen map[uint32]byte | ||||||
expirationBlock *big.Int | ||||||
} | ||||||
senderNoncesLock sync.Mutex | ||||||
|
@@ -124,7 +127,7 @@ func NewRecipientWithSecret(addr ethcommon.Address, broker Broker, val Validator | |||||
secret: secret, | ||||||
maxfacevalue: big.NewInt(0), | ||||||
senderNonces: make(map[string]*struct { | ||||||
nonce uint32 | ||||||
nonceSeen map[uint32]byte | ||||||
expirationBlock *big.Int | ||||||
}), | ||||||
cfg: cfg, | ||||||
|
@@ -363,16 +366,24 @@ func (r *recipient) updateSenderNonce(rand *big.Int, ticket *Ticket) error { | |||||
defer r.senderNoncesLock.Unlock() | ||||||
|
||||||
randStr := rand.String() | ||||||
sn, ok := r.senderNonces[randStr] | ||||||
if ok && ticket.SenderNonce <= sn.nonce { | ||||||
return errors.Errorf("invalid ticket senderNonce sender=%v nonce=%v highest=%v", ticket.Sender.Hex(), ticket.SenderNonce, sn.nonce) | ||||||
senderNonce, randKeySeen := r.senderNonces[randStr] | ||||||
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.
Suggested change
Nit: The plural feels a bit clearer here since the map is tracking a collection of nonces as opposed to a single one. |
||||||
if randKeySeen { | ||||||
_, isSeen := senderNonce.nonceSeen[ticket.SenderNonce] | ||||||
if isSeen { | ||||||
return errors.Errorf("invalid ticket senderNonce: already seen sender=%v nonce=%v", ticket.Sender.Hex(), ticket.SenderNonce) | ||||||
} | ||||||
} else { | ||||||
r.senderNonces[randStr] = &struct { | ||||||
nonceSeen map[uint32]byte | ||||||
expirationBlock *big.Int | ||||||
}{make(map[uint32]byte), ticket.ParamsExpirationBlock} | ||||||
} | ||||||
|
||||||
r.senderNonces[randStr] = &struct { | ||||||
nonce uint32 | ||||||
expirationBlock *big.Int | ||||||
}{ticket.SenderNonce, ticket.ParamsExpirationBlock} | ||||||
|
||||||
// check nonce map size | ||||||
if len(r.senderNonces[randStr].nonceSeen) > maxSenderNonces-1 { | ||||||
cyberj0g marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
return errors.Errorf("invalid ticket senderNonce: too many values sender=%v nonce=%v", ticket.Sender.Hex(), ticket.SenderNonce) | ||||||
} | ||||||
// add new nonce | ||||||
r.senderNonces[randStr].nonceSeen[ticket.SenderNonce] = 1 | ||||||
return nil | ||||||
} | ||||||
|
||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nit: Is there an advantage of using
byte
here instead of abool
?IIUC a
bool
should be 1 byte which would be the same size as abyte
[1] so I don't think there are any storage benefits of usingbyte
. If this is the case, I suggest using abool
as I think using true/false values will be clearer for code readability than using 0/1.[1] Can verify using
unsafe.Sizeof()
on abool
var and abyte
var.