-
Notifications
You must be signed in to change notification settings - Fork 20.1k
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
core/state, light, les: make signature of ContractCode hash-independent #27209
Conversation
light/trie.go
Outdated
@@ -80,14 +80,14 @@ func (db *odrDatabase) ContractCode(addrHash, codeHash common.Hash) ([]byte, err | |||
return code, nil | |||
} | |||
id := *db.id | |||
id.AccKey = addrHash[:] | |||
id.AccKey = addr[:] |
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.
Feels a bit strange to just change a byteslice representing a hash into representing an address. Just changing it doesn't mean it will work, does it?
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.
it won't work if the 'server' doesn't implement this change, but if both client and server do - and if I understand correctly - it will simply replace the hash of the data with the plain address in the request.
I checked that all the locations were updated accordingly, but given the errors in CI, it looks like I missed a point somewhere. I'll wait for Zsolt's input before I fix it, the best approach is still the entire removal of LES if it can be done.
5f9b950
to
95ee5ab
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. LES is going through changes anyway, and it's not working as it is, so that shouldn't be a blocker (?)
@@ -204,7 +204,7 @@ func testIterativeStateSync(t *testing.T, count int, commit bool, bypath bool) { | |||
codeResults = make([]trie.CodeSyncResult, len(codeElements)) | |||
) | |||
for i, element := range codeElements { | |||
data, err := srcDb.ContractCode(common.Hash{}, element.code) | |||
data, err := srcDb.ContractCode(common.Address{}, element.code) |
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.
We must roll out a new snap sync protocol for verkle, later.
In original scheme, contract code is only identified by code hash. While in verkle, contract code is identified by both address and some other information. Therefore, snap protocol has to be changed.
We can just skip it since verkle doesn't support snap sync anyway.
e837e1d
to
59bada1
Compare
@@ -628,13 +622,6 @@ func TestIncompleteStateSync(t *testing.T) { | |||
} | |||
batch.Write() | |||
|
|||
for _, root := range nodehashes { |
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.
It's a very hacky check so that I remove it.
What it does is: iterate the newly added nodes, treat them as the root node of the "sub-trie" and traverse the "sub-trie" respectively. This notion is not compatible in path-based also.
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. @holiman Please take another look.
Just one thing to keep in mind: we need to change snap sync protocol for verkle later.
core/state/database.go
Outdated
@@ -208,7 +209,7 @@ func (db *cachingDB) ContractCode(addrHash, codeHash common.Hash) ([]byte, error | |||
// ContractCodeWithPrefix retrieves a particular contract's code. If the | |||
// code can't be found in the cache, then check the existence with **new** | |||
// db scheme. | |||
func (db *cachingDB) ContractCodeWithPrefix(addrHash, codeHash common.Hash) ([]byte, error) { | |||
func (db *cachingDB) ContractCodeWithPrefix(_, codeHash common.Hash) ([]byte, error) { |
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.
We should make this first parameter a common.Address
to be consistent
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.
Good catch!
@gballet Please take another look. I have fixed all the comments. |
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.
Making of signature of ContractCode hash-independent. Thanks for all you'll hard work.
4daf648
to
b54c50a
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.
@rjl493456442 thanks for your changes, they LGTM. I have rebased on top of master in order to fix the merge error.
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.
Make signature of ContractCode hash-independent.
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!
@@ -27,7 +28,8 @@ import ( | |||
) | |||
|
|||
// nodeIterator is an iterator to traverse the entire state trie post-order, | |||
// including all of the contract code and contract state tries. | |||
// including all of the contract code and contract state tries. Preimage is | |||
// required in order to resolve the contract address. |
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.
Are we sure this is safe? Preimages are not enabled by default AFAIK in Geth, so does this mean node iteration all of a sudden breaks with this PR?
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.
State iterator is useful to traverse the whole state, but it's not UX friendly, because the state keys are all hash instead of raw keys. In order to provide some meaningful information, preimages are still required.
However, we already have the state dumper, IMO we should merge these two together and get rid of one of them.
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.
In case of this PR, state iterator is only used in test, to verify the state completeness, which I think it's a nice tool so I kept it.
…nt (ethereum#27209) * core/state, light, les: make signature of ContractCode hash-independent * push current state for feedback * les: fix unit test * core, les, light: fix les unittests * core/state, trie, les, light: fix state iterator * core, les: address comments * les: fix lint --------- Co-authored-by: Gary Rong <garyrong0905@gmail.com>
…ndependent (ethereum#27209)" This reverts commit bbee228.
…ndependent (ethereum#27209)" This reverts commit bbee228.
Like the previous changes to the
state.Trie
interface, in which functions were modified to use the un-hashed account address instead of its hashed version, the same thing needs to be applied toContractCode
since it takes the hash of the account's address as a parameter.The only major problem is with LES: I have changed the request object to contain the un-hashed address instead of its hash.
Alternatively, it seems to me that this parameter is only used in LES. If we remove LES, then we can remove this parameter entirely.