-
Notifications
You must be signed in to change notification settings - Fork 20.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
core/txpool: move setcode tx validation into legacyPool #31209
Conversation
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 changes look correct to me, but not sure I understand the motivation in the PR?
We have a mechanism for defining tx validation checks that is currently used by both pools. Not every method is implemented by both pools, e.g. FirstNonceGap
is not implemented by the legacy pool. KnownConflicts
is similar where it is optional for pools to implement and so only the legacy pool implements it.
If we go through this PR, we also need to change the comment for UsedAndLeftSlots
because it is currently listed as "mandatory" for pools to implement.
authorization conflict checks are now performed regardless
of whether the transaction is a replacement or not.
could you point out this change for me also? having trouble seeing this in the diff
core/txpool/legacypool/legacypool.go
Outdated
exists = queue.Contains(tx.Nonce()) | ||
} | ||
} | ||
// Replace the existing inflight transaction for delegated accounts |
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.
// Replace the existing inflight transaction for delegated accounts | |
// Replace the existing in-flight transaction for delegated accounts |
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.
Suggested change
// Replace the existing inflight transaction for delegated accounts // Replace the existing in-flight transaction for delegated accounts
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.
Hash Table in JavaScript
A hash table (or hash map) is a data structure that implements an associative array, a structure that can map keys to values. It uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be found.
Key Characteristics:
- Key-Value Pairs: Each entry in a hash table is a key-value pair.
- Hash Function: Converts keys into array indices.
- Efficient Access: Provides average-case O(1) time complexity for lookups, insertions, and deletions.
How It Works:
- Hash Function: A function that takes an input (or 'key') and returns an integer (the 'hash code'), which is used as the index at which the value is stored in the array.
- Collision Handling: When two keys hash to the same index, a collision occurs. Common collision handling methods include:
- Separate Chaining: Each array index points to a linked list of entries that map to the same index.
- Open Addressing: All entry records are stored in the array itself. If a collision occurs, the algorithm searches for the next available slot (probing).
Example in JavaScript:
JavaScript objects are often used as hash tables due to their built-in support for key-value pairs. However, ES6 introduced the Map
object, which is more suitable for hash table implementations.
Using an Object:
const hashTable = {};
// Insert
hashTable["key1"] = "value1";
hashTable["key2"] = "value2";
// Access
console.log(hashTable["key1"]); // Output: value1
// Delete
delete hashTable["key1"];
Using a Map:
const hashTable = new Map();
// Insert
hashTable.set("key1", "value1");
hashTable.set("key2", "value2");
// Access
console.log(hashTable.get("key1")); // Output: value1
// Delete
hashTable.delete("key1");
Conclusion:
Hash tables are a fundamental data structure used for fast data retrieval. While JavaScript objects can be used as hash tables, the Map
object provides a more robust and flexible implementation, especially when dealing with keys that are not strings.
References:
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.
Hash Table in JavaScript
A hash table (or hash map) is a data structure that implements an associative array, a structure that can map keys to values. It uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be found.
Key Characteristics:
- Key-Value Pairs: Each entry in a hash table is a key-value pair.
- Hash Function: Converts keys into array indices.
- Efficient Access: Provides average-case O(1) time complexity for lookups, insertions, and deletions.
How It Works:
- Hash Function: A function that takes an input (or 'key') and returns an integer (the 'hash code'), which is used as the index at which the value is stored in the array.
- Collision Handling: When two keys hash to the same index, a collision occurs. Common collision handling methods include:
- Separate Chaining: Each array index points to a linked list of entries that map to the same index.
- Open Addressing: All entry records are stored in the array itself. If a collision occurs, the algorithm searches for the next available slot (probing).
Example in JavaScript:
JavaScript objects are often used as hash tables due to their built-in support for key-value pairs. However, ES6 introduced the Map
object, which is more suitable for hash table implementations.
Using an Object:
const hashTable = {};
// Insert
hashTable["key1"] = "value1";
hashTable["key2"] = "value2";
// Access
console.log(hashTable["key1"]); // Output: value1
// Delete
delete hashTable["key1"];
Using a Map:
const hashTable = new Map();
// Insert
hashTable.set("key1", "value1");
hashTable.set("key2", "value2");
// Access
console.log(hashTable.get("key1")); // Output: value1
// Delete
hashTable.delete("key1");
Conclusion:
Hash tables are a fundamental data structure used for fast data retrieval. While JavaScript objects can be used as hash tables, the Map
object provides a more robust and flexible implementation, especially when dealing with keys that are not strings.
References:
core/txpool/legacypool/legacypool.go
Outdated
queue := pool.queue[from] | ||
if queue != nil { | ||
count += queue.Len() | ||
if !exists { |
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.
if !exists { | |
exists = queue.Contains(tx.Nonce()) || exists |
simpler ?
The primary motivation is to keep common validation as generic as possible and not to
It's true that legacyPool doesn't need to check the nonce gap. But it's the technical debt Checking nonce is a very common requirement, while auth conflict is very specific to
This |
Okay I see what you mean where Since you have already implemented I suppose we can just accept this. Once we fix the nits on this PR it can be merged. |
Yep, we should definitely fix the @fjl How do you feel about the changes of relocating the setcode-tx specific validations to the legacypool? Would be nice to have some inputs from your side |
1168004
to
8d562a4
Compare
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.
LGTM - will give Felix a couple days in case he wants to weigh in
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.
LGTM, but I agree with @lightclient that we should probably get rid of the validationOptionsWithState in favor of some code duplication since it isn't a great abstraction
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.
Hash Table in JavaScript
A hash table (or hash map) is a data structure that implements an associative array, a structure that can map keys to values. It uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be found.
Key Characteristics:
- Key-Value Pairs: Each entry in a hash table is a key-value pair.
- Hash Function: Converts keys into array indices.
- Efficient Access: Provides average-case O(1) time complexity for lookups, insertions, and deletions.
How It Works:
- Hash Function: A function that takes an input (or 'key') and returns an integer (the 'hash code'), which is used as the index at which the value is stored in the array.
- Collision Handling: When two keys hash to the same index, a collision occurs. Common collision handling methods include:
- Separate Chaining: Each array index points to a linked list of entries that map to the same index.
- Open Addressing: All entry records are stored in the array itself. If a collision occurs, the algorithm searches for the next available slot (probing).
Example in JavaScript:
JavaScript objects are often used as hash tables due to their built-in support for key-value pairs. However, ES6 introduced the Map
object, which is more suitable for hash table implementations.
Using an Object:
const hashTable = {};
// Insert
hashTable["key1"] = "value1";
hashTable["key2"] = "value2";
// Access
console.log(hashTable["key1"]); // Output: value1
// Delete
delete hashTable["key1"];
Using a Map:
const hashTable = new Map();
// Insert
hashTable.set("key1", "value1");
hashTable.set("key2", "value2");
// Access
console.log(hashTable.get("key1")); // Output: value1
// Delete
hashTable.delete("key1");
Conclusion:
Hash tables are a fundamental data structure used for fast data retrieval. While JavaScript objects can be used as hash tables, the Map
object provides a more robust and flexible implementation, especially when dealing with keys that are not strings.
In this PR, several improvements have been made:
Authorization-related validations have been moved to legacyPool.
Previously, these checks were part of the standard validation procedure,
which applies common validations across different pools. Since these
checks are specific to SetCode transactions, relocating them to legacyPool
is a more reasonable choice.
Additionally, authorization conflict checks are now performed regardless
of whether the transaction is a replacement or not.