@@ -29,53 +29,59 @@ import (
2929// other packages. A call to RegisterExtras is required for the rest of this 
3030// package to function correctly. 
3131func  RegisterExtras () {
32- 	extras  =  trienode .RegisterExtras [proposal ,  proposal , struct {}]()
32+ 	extras  =  trienode .RegisterExtras [proposals ,  proposals , struct {}]()
3333}
3434
35- var  extras  trienode.ExtraPayloads [* proposal , * proposal , * struct {}]
35+ var  extras  trienode.ExtraPayloads [* proposals , * proposals , * struct {}]
3636
37- // A proposal is embedded as a payload in the [trienode.NodeSet] object returned 
38- // by trie `Commit()`. A preceding call to [RegisterExtras] ensures that the 
39- // proposal will be propagated to [Database.Update]. 
40- // 
41- // After construction, [proposal.setFinalizer] SHOULD be called to ensure 
42- // release of resources via [proposal.free] once the proposal is garbage 
43- // collected. 
44- type  proposal  struct  {
37+ // A proposals carrier is embedded as a payload in the [trienode.NodeSet] object 
38+ // returned by trie `Commit()`. A preceding call to [RegisterExtras] ensures 
39+ // that the proposals will be propagated to [Database.Update]. 
40+ type  proposals  struct  {
4541	// root MUST match the argument returned by the trie's `Commit()` method. 
4642	root  common.Hash 
47- 
48- 	// TODO(alarso16) add handles etc. here and clean them up in [proposal.free] 
49- 
50- 	finalized  chan  struct {} // https://go.dev/doc/gc-guide#Testing_object_death 
43+ 	// handles MAY carry >=1 handle, based off different parents, but all MUST 
44+ 	// result in the same root (i.e. the one specified in the other field). 
45+ 	handles  []* handle 
5146}
5247
53- func  (p  * proposal ) injectInto (ns  * trienode.NodeSet ) {
48+ func  (p  * proposals ) injectInto (ns  * trienode.NodeSet ) {
5449	extras .NodeSet .Set (ns , p )
5550}
5651
52+ // A handle carries a Firewood FFI proposal handle (i.e. Rust-owned memory). 
53+ // After construction, [handle.setFinalizer] SHOULD be called to ensure release 
54+ // of resources via [handle.free] once the handle is garbage collected. 
55+ type  handle  struct  {
56+ 	// TODO(alarso16) place the FFI handle here 
57+ 
58+ 	// finalized is set by [handle.setFinalizer] to signal when said finalizer 
59+ 	// has run; see https://go.dev/doc/gc-guide#Testing_object_death 
60+ 	finalized  chan  struct {}
61+ }
62+ 
5763// setFinalizer calls [runtime.SetFinalizer] with `p`. 
58- func  (p   * proposal ) setFinalizer () {
59- 	p .finalized  =  make (chan  struct {})
60- 	runtime .SetFinalizer (p , (* proposal ).finalizer )
64+ func  (h   * handle ) setFinalizer () {
65+ 	h .finalized  =  make (chan  struct {})
66+ 	runtime .SetFinalizer (h , (* handle ).finalizer )
6167}
6268
6369// finalizer is expected to be passed to [runtime.SetFinalizer], abstracted as a 
6470// method to guarantee that it doesn't accidentally capture the value being 
6571// collected, thus resurrecting it. 
66- func  (p   * proposal ) finalizer () {
67- 	p .free ()
68- 	close (p .finalized )
72+ func  (h   * handle ) finalizer () {
73+ 	h .free ()
74+ 	close (h .finalized )
6975}
7076
7177// free is called when the [proposal] is no longer reachable. 
72- func  (p   * proposal ) free () {
78+ func  (h   * handle ) free () {
7379	// TODO(alarso16) free the Rust object(s). 
7480}
7581
7682// AfterMergeNodeSet implements [trienode.MergedNodeSetHooks], copying at most 
7783// one proposal handle into the merged set. 
78- func  (h   * proposal ) AfterMergeNodeSet (into  * trienode.MergedNodeSet , ns  * trienode.NodeSet ) error  {
84+ func  (p   * proposals ) AfterMergeNodeSet (into  * trienode.MergedNodeSet , ns  * trienode.NodeSet ) error  {
7985	if  p  :=  extras .MergedNodeSet .Get (into ); p .root  !=  (common.Hash {}) {
8086		return  fmt .Errorf (">1 %T carrying non-zero %T" , ns , p )
8187	}
@@ -86,4 +92,4 @@ func (h *proposal) AfterMergeNodeSet(into *trienode.MergedNodeSet, ns *trienode.
8692}
8793
8894// AfterAddNode implements [trienode.NodeSetHooks] as a noop. 
89- func  (h   * proposal ) AfterAddNode (* trienode.NodeSet , []byte , * trienode.Node ) {}
95+ func  (p   * proposals ) AfterAddNode (* trienode.NodeSet , []byte , * trienode.Node ) {}
0 commit comments