-
Notifications
You must be signed in to change notification settings - Fork 0
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
remove nonce removal leftovers #5
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 |
---|---|---|
|
@@ -42,7 +42,6 @@ func setEvents(c *wctl.Client) (func(), error) { | |
c.OnGasBalanceUpdated = onGasBalanceUpdated | ||
c.OnStakeUpdated = onStakeUpdated | ||
c.OnRewardUpdated = onRewardUpdate | ||
c.OnNonceUpdated = onNonceUpdated | ||
|
||
if err := addToCloser(&toClose)(c.PollAccounts()); err != nil { | ||
return cleanup, err | ||
|
@@ -169,13 +168,6 @@ func onRewardUpdate(u wctl.RewardUpdated) { | |
Msg("Reward updated.") | ||
} | ||
|
||
func onNonceUpdated(u wctl.NonceUpdated) { | ||
logger.Info(). | ||
Hex("public_key", u.AccountID[:]). | ||
Uint64("nonce", u.Nonce). | ||
Msg("Nonce updated.") | ||
} | ||
|
||
func onPeerJoin(u wctl.PeerJoin) { | ||
logger.Info(). | ||
Hex("public_key", u.AccountID[:]). | ||
Comment on lines
172
to
173
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. The logging in this function uses structured logging, which is good for clarity and consistency. However, care must be taken to ensure that sensitive information is not logged, and that the logging mechanism is secure against injection attacks. Suggested Improvement: 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. Micro-Learning Topic: Injection attack (Detected by phrase)Matched on "injection attack"Injection flaws, such as SQL, NoSQL, OS, and LDAP injection, occur when untrusted data is sent to an interpreter as part of a command or query. The attacker’s hostile data can trick the interpreter into executing unintended commands or accessing data without proper authorization. Source: https://www.owasp.org/index.php/Category:OWASP_Top_Ten_Project Try a challenge in Secure Code WarriorHelpful references
Micro-Learning Topic: Log injection (Detected by phrase)Matched on "log injection"The Log Forging vulnerability is caused by writing unvalidated user input to log files can allow an attacker to forge log entries or inject malicious content into the logs. Try a challenge in Secure Code WarriorHelpful references
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,7 +131,6 @@ type CollapseContext struct { | |
balances map[AccountID]uint64 | ||
stakes map[AccountID]uint64 | ||
rewards map[AccountID]uint64 | ||
nonces map[AccountID]uint64 | ||
contracts map[TransactionID][]byte | ||
contractGasBalances map[TransactionID]uint64 | ||
contractVMs map[AccountID]*VMState | ||
|
@@ -160,7 +159,6 @@ func (c *CollapseContext) init() { | |
c.balances = make(map[AccountID]uint64) | ||
c.stakes = make(map[AccountID]uint64) | ||
c.rewards = make(map[AccountID]uint64) | ||
c.nonces = make(map[AccountID]uint64) | ||
c.contracts = make(map[TransactionID][]byte) | ||
c.contractGasBalances = make(map[TransactionID]uint64) | ||
c.contractVMs = make(map[AccountID]*VMState) | ||
Comment on lines
159
to
164
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. Suggestion: Optimize Memory Usage by Specifying Initial Map CapacitiesWhen initializing maps in the For example, if you expect the number of accounts to not exceed 1000 initially, you could initialize the c.balances = make(map[AccountID]uint64, 1000) This change could prevent frequent reallocations as the map grows, leading to more efficient memory usage. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,17 +47,6 @@ Upon the creation of a transaction, the transaction creator would sign the tag, | |
would play the role of being the transactions sender. The sender would then assign consensus-related information to the transaction, sign the entirety of | ||
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. nitpick (documentation): Add missing apostrophe in 'transactions sender' |
||
the transaction, and broadcast it out to the network to be verified and finalized by other Wavelet nodes. | ||
|
||
## Replay Attacks | ||
|
||
A nonce is associated to each and every Wavelet account. A nonce is an incremental, ascending counter that gets incremented every single time a transaction | ||
that was created by some given account gets finalized and apply to the ledgers state. | ||
|
||
The nonce is used to prevent replay attacks, where after an account creates a transaction, there may exist a possibility that several nodes may attempt | ||
to re-sign the transaction such that the transaction may operate and be applied on the ledger indefinite amounts of times. | ||
|
||
By attaching a nonce counter, once a single instance of some accounts transaction gets finalized, no other node may re-sign and re-broadcast the transaction | ||
to cause a replay attack. | ||
|
||
## Binary Format | ||
|
||
Transactions are encoded using a simple binary encoding scheme, where all integers are little-endian encoded, and all variable-sized arrays are | ||
|
@@ -70,7 +59,7 @@ The current binary format of a Wavelet transaction is denoted as follows: | |
| Flag | A single byte that is 1 if the Creator Account ID is the same as the Sender Account ID, and is 0 otherwise. | | ||
| Sender Account ID | 256-bit wallet address/public key. | | ||
| Creator Account ID | 256-bit wallet address/public key. | | ||
| Nonce | Latest nonce value of the creators account, denoted as an unsigned 64-bit little-endian integer. | | ||
| Nonce | Unique value, denoted as an unsigned 64-bit little-endian integer. | | ||
| Parent IDs | Length-prefixed array of 256-bit transaction IDs; assigned by the transactions sender. | | ||
| Parent Seeds | Array of 256-bit transaction seeds, with the same length as the Parent IDs field and therefore not length-prefixed; must correspond to the transactions specified by Parent IDs. | | ||
| Depth | Unsigned 64-bit little-endian integer; assigned by the transactions sender. | | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -533,4 +533,4 @@ func TestCollectVotesForSync(t *testing.T) { | |
|
||
assert.False(t, snowball.Decided()) | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,7 +104,6 @@ type Client struct { | |
OnNumPagesUpdated | ||
OnStakeUpdated | ||
OnRewardUpdated | ||
OnNonceUpdated | ||
|
||
// Network | ||
OnPeerJoin | ||
Comment on lines
104
to
109
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. The callback fields defined in the type PeerEventHandler func(peerID string) error
OnPeerJoin PeerEventHandler
OnPeerLeave PeerEventHandler This change would make the code more robust by enforcing the correct type of function to be assigned to each callback, reducing the risk of runtime errors.
Comment on lines
104
to
109
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. The callbacks defined (e.g., type UpdateHandler func() error
OnNumPagesUpdated UpdateHandler
OnStakeUpdated UpdateHandler This modification ensures that errors are not silently ignored and are handled appropriately, enhancing the reliability of the system. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,13 +43,6 @@ type ( | |
Time time.Time `json:"time"` | ||
} | ||
OnRewardUpdated = func(RewardUpdated) | ||
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. The Example: OnRewardUpdated = func(RewardUpdated) error |
||
|
||
NonceUpdated struct { | ||
AccountID [32]byte `json:"account_id"` | ||
Nonce uint64 `json:"nonce"` | ||
Time time.Time `json:"time"` | ||
} | ||
OnNonceUpdated = func(NonceUpdated) | ||
) | ||
|
||
// Mod: network | ||
|
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.
The error handling in this block is straightforward but could be enhanced by providing more context-specific error messages or handling specific error types differently. This would improve the maintainability and debuggability of the code.
Suggested Improvement:
Consider enhancing the error handling by checking for specific error types and handling them accordingly. This could involve retrying the operation, logging additional details, or taking other corrective actions based on the nature of the error.