-
Notifications
You must be signed in to change notification settings - Fork 845
perf: Share proposal between hash and commit #4697
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
76925ee
perf: Share proposal between hash and commit
alarso16 c6ec619
fix: Empty genesis
alarso16 98dfe7f
fix: license headers
alarso16 9961f98
style: rename
alarso16 7f911f4
chore: metrics and cleanup
alarso16 2eea576
fix: copilot comments
alarso16 95aaed8
Merge remote-tracking branch 'origin/master' into alarso16/firewood-p…
alarso16 4685477
fix: remove race in possible map
alarso16 4dd2920
Merge remote-tracking branch 'origin/master' into alarso16/firewood-p…
alarso16 e295fda
fix: wrong order of error handling
alarso16 7a5f6aa
chore: lint
alarso16 e2e94a0
refactor: Use Blockchain state to populate existing (#4835)
alarso16 b37c314
chore: rename function
alarso16 26c700e
Merge remote-tracking branch 'origin/master' into alarso16/firewood-p…
alarso16 6294748
test: Add basic tests
alarso16 93f3d7e
test: Allow mistakes to be corrected on Update
alarso16 015675b
Firewood v0.1.0 (#4890)
alarso16 d5dff00
Revert "Firewood v0.1.0" (#4892)
alarso16 ea1c6db
refactor: Commit instead of SetHashAndHeight in genesis
alarso16 29c20b7
fix: use empty root hash
alarso16 65db2c5
refactor: Infer empty genesis state
alarso16 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. | ||
alarso16 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| package firewood | ||
|
|
||
| import ( | ||
| "encoding/binary" | ||
| "fmt" | ||
|
|
||
| "github.com/ava-labs/libevm/common" | ||
| "github.com/ava-labs/libevm/ethdb" | ||
| ) | ||
|
|
||
| const ( | ||
| committedBlockHashKey = "committedFirewoodBlockHash" | ||
| committedHeightKey = "committedFirewoodHeight" | ||
| ) | ||
|
|
||
| // ReadCommittedBlockHash retrieves the most recently committed block hash from the key-value store. | ||
| func ReadCommittedBlockHashes(kvStore ethdb.Database) (map[common.Hash]struct{}, error) { | ||
| data, _ := kvStore.Get([]byte(committedBlockHashKey)) // ignore not found error | ||
| if len(data)%common.HashLength != 0 { | ||
| return nil, fmt.Errorf("invalid committed block hash length: expected multiple of %d, got %d", common.HashLength, len(data)) | ||
| } | ||
| hashes := make(map[common.Hash]struct{}) | ||
| if len(data) == 0 { | ||
| hashes[common.Hash{}] = struct{}{} | ||
| return hashes, nil | ||
| } | ||
| for i := 0; i < len(data); i += common.HashLength { | ||
| hash := common.BytesToHash(data[i : i+common.HashLength]) | ||
| hashes[hash] = struct{}{} | ||
| } | ||
| return hashes, nil | ||
| } | ||
|
|
||
| // WriteCommittedBlockHash writes the most recently committed block hash to the key-value store. | ||
| func WriteCommittedBlockHashes(kvStore ethdb.Database, hashes map[common.Hash]struct{}) error { | ||
| contents := make([]byte, 0, len(hashes)*common.HashLength) | ||
| for hash := range hashes { | ||
| contents = append(contents, hash.Bytes()...) | ||
| } | ||
| if err := kvStore.Put([]byte(committedBlockHashKey), contents); err != nil { | ||
| return fmt.Errorf("error writing committed block hashes: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // ReadCommittedHeight retrieves the most recently committed height from the key-value store. | ||
| func ReadCommittedHeight(kvStore ethdb.Database) uint64 { | ||
| data, _ := kvStore.Get([]byte(committedHeightKey)) | ||
| if len(data) != 8 { | ||
| return 0 | ||
| } | ||
| return binary.BigEndian.Uint64(data) | ||
| } | ||
|
|
||
| // WriteCommittedHeight writes the most recently committed height to the key-value store. | ||
| func WriteCommittedHeight(kvStore ethdb.Database, height uint64) error { | ||
| enc := make([]byte, 8) | ||
| binary.BigEndian.PutUint64(enc, height) | ||
| if err := kvStore.Put([]byte(committedHeightKey), enc); err != nil { | ||
| return fmt.Errorf("error writing committed height: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.