-
Notifications
You must be signed in to change notification settings - Fork 21
feat(ffi-iterator): Implementation of Iterator in Go (2/4) #1256
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 all commits
Commits
Show all changes
186 commits
Select commit
Hold shift + click to select a range
6261968
feat: initial implementation of ffi iterator
AminR443 071a5eb
feat: better go interface for iterator, edge case fixes
AminR443 28bc2a8
style: cargo fmt
AminR443 9d1ef4b
Merge branch 'main' into amin/ffi-iterator
AminR443 23f7e6d
fix: tiny issues after merge
AminR443 3295568
fix: test clippy error, better test case
AminR443 4029d20
feat: better iterator abstraction in ffi, iter_on_root
AminR443 96acf50
chore: only include firewood crate changes to make pr smaller
AminR443 0be5eb0
fix: apply suggestions, add docs, add tests
AminR443 316f9a3
Merge branch 'main' into amin/ffi-iterator-base
AminR443 338a4c9
fix: stuff from merge, style
AminR443 4d08b12
fix: format variable for clippy
AminR443 3ea4f7f
feat: better abstraction, deduplication in DbViewSyncBytes
AminR443 7cfa1cf
test: add tests for iterate, fix tiny issues
AminR443 8ec3991
ci: trigger tests
AminR443 40671f1
Merge branch 'main' into amin/ffi-iterator-base
AminR443 bde139e
test: add fuzz test for iterate
AminR443 b1546f2
Merge branch 'main' into amin/ffi-iterator-base
AminR443 3f76257
wip: new iterator
AminR443 74ff74b
feat: merkle_ref for supporting arc in merklenodestream
AminR443 236a710
merge: needed new parts from ffi-iterator-base
AminR443 b1586d7
fix: missed stuff, fmt
AminR443 bce4d7d
feat: all ffi methods initial impl
AminR443 4c8a2bb
feat: go ffi, tidy rust ffi and use borrowed
AminR443 10c9551
chore: remove go side for now
AminR443 a42aae2
feat: iter_on_proposal, code cleanup
AminR443 b17113e
todo: key value note
AminR443 7440a5f
feat(async-removal): Phase 1 - lint on `clippy::unused_async`
demosdemon 84ff6ce
feat(async-removal): Phase 2 - make `Proposal` trait sync
demosdemon 6d05477
feat(async-removal): Phase 3 - make `Db` trait sync
demosdemon cc95f6d
Merge branch 'main' into brandon.leblanc/remove-async-p2
demosdemon 83a3c77
Merge branch 'brandon.leblanc/remove-async-p2' into brandon.leblanc/r…
demosdemon 16fe8be
Merge branch 'main' into amin/ffi-iterator-new
AminR443 a47843b
Merge branch 'main' into brandon.leblanc/remove-async-p2
demosdemon e7540bf
Merge branch 'brandon.leblanc/remove-async-p2' into brandon.leblanc/r…
demosdemon d0d8b2b
Merge branch 'main' into brandon.leblanc/remove-async-p2
demosdemon f6ca77a
Merge branch 'brandon.leblanc/remove-async-p2' into brandon.leblanc/r…
demosdemon dd3f3cf
Merge branch 'main' into brandon.leblanc/remove-async-p3
demosdemon ce44145
Merge branch 'main' into amin/ffi-iterator-new
AminR443 c1452a3
refactor: better types
AminR443 eeee17e
Merge branch 'main' into brandon.leblanc/remove-async-p3
demosdemon f07184e
feat(async-removal): Phase 4 - Make `DbView` synchronous
demosdemon 4d8db9d
missed some
demosdemon 28dc159
fix metrics
demosdemon e330a0b
fix benchmark again
demosdemon 89c0d9b
make tokio/prometheus optional
demosdemon 43227dc
add grpc-testtool back (even though it's broken)
demosdemon 2e387c2
replace DbViewSyncBytes with ArcDynDbView
demosdemon 64ce27a
comment typo
demosdemon ae15477
cleanup
demosdemon 56ab74e
remove commented code
demosdemon 87bd241
more cleanup
demosdemon b1d847a
fix root ethhash
demosdemon bf766d1
Merge remote-tracking branch 'origin/main' into brandon.leblanc/remov…
demosdemon c30c847
lifetime label consistency
demosdemon d27fd65
extension trait
demosdemon 628668d
Merge branch 'main' into brandon.leblanc/remove-async-p4
demosdemon 79815d1
remove needless impls
demosdemon ad310a2
nit-picky change
demosdemon 468291b
move try_extend into its own module and add test
demosdemon 7b2279f
update test
demosdemon 94d6dec
collapse trait bounds
demosdemon d034c8a
wip: merge remote-tracking branch 'origin/brandon.leblanc/remove-asyn…
AminR443 3a0ae2d
feat: OwnedIterView and use new sync api
AminR443 7dee974
feat(ffi-refactor): replace sequence id with pointer to proposals (8/8)
demosdemon a5ba724
Merge branch 'amin/ffi-iterator-sync' into amin/ffi-iterator-new
AminR443 5949620
Merge branch 'main' into amin/ffi-iterator-new
AminR443 1ee07d9
fix: merge errors
AminR443 546ffc8
Merge remote-tracking branch 'origin/brandon.leblanc/ffi-refactor' in…
AminR443 d80c022
feat: iterator with new ffi structure
AminR443 3f06f81
chore: remove irrelevant comments
AminR443 8020a02
fix: cargo fmt
AminR443 247fcad
feat: add docs, cleanup
AminR443 c8b88e1
fmt: .
AminR443 3b76b12
feat: squash merge from ffi-iterator-performance, update changes to n…
AminR443 cac3755
feat: iter on proposal for go, tests, fix latest revision issue
AminR443 53fb5f4
Merge branch 'main' into brandon.leblanc/ffi-refactor
demosdemon 7efdf98
Merge branch 'main' into brandon.leblanc/ffi-refactor
demosdemon 8efa4bf
fmt: ...
AminR443 1858a9b
fix: uniform behaviour for empty db (ethhash)
AminR443 ce94989
fix: golangci-lint issues
AminR443 1a2a37e
review: apply pr comments
AminR443 f50427d
feat: better iter interface for views, clean code, better docs
AminR443 b828883
fix: doc ref
AminR443 9071f19
Merge remote-tracking branch 'origin/main' into brandon.leblanc/ffi-r…
demosdemon 483538f
use something adding in merge
demosdemon d8ebb92
Merge remote-tracking branch 'origin/main' into brandon.leblanc/ffi-r…
demosdemon 87515fc
errant change from resolving merge conflicts
demosdemon 6b1e3af
start moving things out of memory.go
demosdemon 8171ef7
fix doc error
demosdemon fcac3a8
Merge remote-tracking branch 'origin/brandon.leblanc/ffi-refactor' in…
AminR443 bafc8ad
Merge branch 'amin/ffi-iterator-p1' into amin/ffi-iterator-p2
AminR443 f15635c
fix: apply first round of suggestions by austin
AminR443 b3f8654
fix: apply second round of suggestions by austin
AminR443 e4374f3
feat: drop rust iterator automatically if exhausted
AminR443 d3e2ac7
Merge branch 'main' into brandon.leblanc/ffi-refactor
demosdemon c04104b
feat!: rename `Hashable::key`
demosdemon 6792c2f
put back the filtered child_hashes
demosdemon 1d1c29a
comments
demosdemon 1705b44
correct comments on the trait
demosdemon b7cf054
fix: add suggested changes
AminR443 acf3e94
feat(proofs)!: add v0 serialization for RangeProofs
demosdemon eb9e4ec
go fmt
demosdemon febb68e
update err to match on both ethhash and not
demosdemon 49f9366
ensure partial range proofs generate and serialize
demosdemon ec8ee02
Merge branch 'main' into brandon.leblanc/ffi-refactor
demosdemon c3e0da7
feedback updates
demosdemon 9cc3c53
golint
demosdemon 7802d5e
update documentation
demosdemon 40c33cc
make ChildrenMap generic
demosdemon 3629d76
fix docs
demosdemon ccc5f1c
Merge branch 'brandon.leblanc/hashable-trait-methods' into brandon.le…
demosdemon d182370
Merge branch 'brandon.leblanc/serialized-range-proofs' into brandon.l…
demosdemon 7aaa681
more tests and document the DOS
demosdemon 6b33cf2
simplify tests
demosdemon 31648d7
consistency
demosdemon e84ae42
rewrite reader to be easier to read
demosdemon 60b54ae
finish moving things around
demosdemon f0375c4
fix docs
demosdemon 72a444d
hide ProofType too
demosdemon 4ed5534
Merge branch 'brandon.leblanc/serialized-range-proofs' into brandon.l…
demosdemon b46ca19
check that the keys drom the dropped proposal are not in the db
demosdemon 7508405
Merge branch 'main' into brandon.leblanc/hashable-trait-methods
demosdemon 21ba3b7
Merge branch 'brandon.leblanc/hashable-trait-methods' into brandon.le…
demosdemon 3669d24
Merge branch 'brandon.leblanc/serialized-range-proofs' into brandon.l…
demosdemon 5e7cca7
fix(range-proofs): serialize range proof key consistently
demosdemon 6a6648d
Merge remote-tracking branch 'origin/main' into brandon.leblanc/seria…
demosdemon b818975
Merge remote-tracking branch 'origin/main' into brandon.leblanc/fix-l…
demosdemon 7ab26ab
Merge branch 'main' into brandon.leblanc/serialized-range-proofs
demosdemon 6348f89
fix(range-proofs): fix verify of exclusion proofs
demosdemon 4a6a77d
Merge branch 'brandon.leblanc/fix-left-exclusion-proof' into brandon.…
demosdemon 662daa3
Merge branch 'main' into brandon.leblanc/fix-left-exclusion-proof
demosdemon ff250bc
Merge branch 'brandon.leblanc/fix-left-exclusion-proof' into brandon.…
demosdemon e57666a
fix for ethhash
demosdemon e4f8ee8
Merge branch 'brandon.leblanc/fix-left-exclusion-proof' into brandon.…
demosdemon 07bf0d1
Merge branch 'brandon.leblanc/serialized-range-proofs' into brandon.l…
demosdemon 7580057
Merge remote-tracking branch 'origin/brandon.leblanc/fix-verify-exclu…
demosdemon 228b463
Merge remote-tracking branch 'origin/main' into brandon.leblanc/ffi-r…
demosdemon ec865c8
Merge branch 'main' into brandon.leblanc/ffi-refactor
demosdemon 5266c78
Merge branch 'main' into brandon.leblanc/ffi-refactor
demosdemon fcc07b8
Merge branch 'main' into brandon.leblanc/ffi-refactor
demosdemon e818456
wip: step 1, revision ground work
AminR443 3fbb4ae
docs: add documentation for methods
AminR443 deced79
feat: impl dbview for revision manager
AminR443 9ecadd8
docs: add docs
AminR443 97bc262
feat: hook up go side with the revisions
AminR443 f175b7a
docs: go
AminR443 3ba04e5
feat: add free
AminR443 9220cb7
doc+test: revision
AminR443 3c351ac
fix: typo
AminR443 efc7bf0
fmt: ...
AminR443 8db0b58
fmt: clippy
AminR443 0a57f71
fmt: ...
AminR443 29d4ccc
Merge commit 'fcc07b8ba5e0716e3d8892a275010e77daaebbe5' into amin/ffi…
AminR443 60eb9e7
Merge commit '8df1ccc1464f58839c732b57c6cd703e88137abc' into amin/ffi…
AminR443 340058d
Merge remote-tracking branch 'origin/main' into amin/ffi-iterator-p1
AminR443 f1177df
chore: cargo.lock update
AminR443 1d98216
Merge branch 'amin/ffi-revision' into amin/ffi-iterator-p1
AminR443 975fe4c
feat: integrate with revision handle
AminR443 96ce89d
docs: ..
AminR443 4e1398b
fix: docs issue
AminR443 332fba7
Merge branch 'amin/ffi-revision' into amin/ffi-iterator-p1
AminR443 42ef414
fmt: ...
AminR443 c0c126d
wip: merge p1
AminR443 b37adaf
feat: make iter go interface compatible with revisions
AminR443 193563f
review: apply Ron's suggestions
AminR443 ac53d8d
fix: docs
AminR443 bda609d
fmt: ...
AminR443 6ea9dbf
Merge branch 'amin/ffi-iterator-p1' into amin/ffi-iterator-p2
AminR443 38ce865
fix: make it work with p1 changes
AminR443 dbcf8cf
test: add revision lifetime showcase
AminR443 ca451df
test: add revision lifetime showcase/reaping
AminR443 9a5c66e
feat: brandon's suggestions
AminR443 15a7b40
Merge branch 'main' into amin/ffi-revision
AminR443 1902e23
Merge branch 'amin/ffi-revision' into amin/ffi-iterator-p1
AminR443 24da907
Merge branch 'amin/ffi-iterator-p1' into amin/ffi-iterator-p2
AminR443 4ec6ad7
clippy: ...
AminR443 dc6a000
Merge branch 'main' into amin/ffi-revision
AminR443 101b119
fix: cargo.lock anomaly
AminR443 be6728b
Merge branch 'main' into amin/ffi-revision
AminR443 57cb082
docs: clarification
AminR443 e42f063
Merge branch 'main' into amin/ffi-revision
AminR443 27a0688
Merge branch 'amin/ffi-revision' into amin/ffi-iterator-p1
AminR443 91d3882
Merge branch 'main' into amin/ffi-iterator-p1
AminR443 ab7f1ad
Merge branch 'amin/ffi-iterator-p1' into amin/ffi-iterator-p2
AminR443 6a7dbcc
Merge branch 'main' into amin/ffi-iterator-p2
AminR443 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright (C) 2025, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE.md for licensing terms. | ||
|
||
package ffi | ||
|
||
// #include <stdlib.h> | ||
// #include "firewood.h" | ||
import "C" | ||
|
||
import ( | ||
"fmt" | ||
"unsafe" | ||
) | ||
|
||
type Iterator struct { | ||
// handle is an opaque pointer to the iterator within Firewood. It should be | ||
// passed to the C FFI functions that operate on iterators | ||
// | ||
// It is not safe to call these methods with a nil handle. | ||
handle *C.IteratorHandle | ||
|
||
// currentKey is the current key retrieved from the iterator | ||
currentKey []byte | ||
// currentVal is the current value retrieved from the iterator | ||
currentVal []byte | ||
// err is the error from the iterator, if any | ||
err error | ||
} | ||
|
||
// Next proceeds to the next item on the iterator, and returns true | ||
// if succeeded and there is a pair available. | ||
// The new pair could be retrieved with Key and Value methods. | ||
func (it *Iterator) Next() bool { | ||
AminR443 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
kv, e := getKeyValueFromKeyValueResult(C.fwd_iter_next(it.handle)) | ||
it.err = e | ||
if kv == nil || e != nil { | ||
return false | ||
} | ||
k, v, e := kv.Consume() | ||
it.currentKey = k | ||
it.currentVal = v | ||
it.err = e | ||
return e == nil | ||
} | ||
|
||
// Key returns the key of the current pair | ||
func (it *Iterator) Key() []byte { | ||
if (it.currentKey == nil && it.currentVal == nil) || it.err != nil { | ||
return nil | ||
} | ||
return it.currentKey | ||
} | ||
|
||
// Value returns the value of the current pair | ||
func (it *Iterator) Value() []byte { | ||
AminR443 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (it.currentKey == nil && it.currentVal == nil) || it.err != nil { | ||
return nil | ||
} | ||
return it.currentVal | ||
} | ||
|
||
// Err returns the error if Next failed | ||
func (it *Iterator) Err() error { | ||
return it.err | ||
} | ||
|
||
// Drop drops the iterator and releases the resources | ||
func (it *Iterator) Drop() error { | ||
AminR443 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if it.handle != nil { | ||
return getErrorFromVoidResult(C.fwd_free_iterator(it.handle)) | ||
} | ||
return nil | ||
} | ||
|
||
// getIteratorFromIteratorResult converts a C.IteratorResult to an Iterator or error. | ||
func getIteratorFromIteratorResult(result C.IteratorResult) (*Iterator, error) { | ||
switch result.tag { | ||
case C.IteratorResult_NullHandlePointer: | ||
return nil, errDBClosed | ||
case C.IteratorResult_Ok: | ||
body := (*C.IteratorResult_Ok_Body)(unsafe.Pointer(&result.anon0)) | ||
proposal := &Iterator{ | ||
handle: body.handle, | ||
} | ||
return proposal, nil | ||
case C.IteratorResult_Err: | ||
err := newOwnedBytes(*(*C.OwnedBytes)(unsafe.Pointer(&result.anon0))).intoError() | ||
return nil, err | ||
default: | ||
return nil, fmt.Errorf("unknown C.IteratorResult tag: %d", result.tag) | ||
} | ||
} |
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
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.