From 0636a3d499de9e2ff4dc62c428c2e47b0ab97097 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 2 Aug 2021 14:09:02 -0500 Subject: [PATCH 01/11] extension node will never contain TrieNode directly --- gen.go | 5 +-- trie/marshal.go | 83 +++++++---------------------------------------- trie/unmarshal.go | 67 +++----------------------------------- 3 files changed, 19 insertions(+), 136 deletions(-) diff --git a/gen.go b/gen.go index b70c2f4..a64af00 100644 --- a/gen.go +++ b/gen.go @@ -262,7 +262,7 @@ func accumulateStateDataStructures(ts *schema.TypeSystem) { type TrieExtensionNode struct { PartialPath Bytes - Child Child + Child &TrieNode } type TrieLeafNode struct { @@ -319,10 +319,11 @@ func accumulateStateDataStructures(ts *schema.TypeSystem) { ts.Accumulate(schema.SpawnStruct("TrieExtensionNode", []schema.StructField{ schema.SpawnStructField("PartialPath", "Bytes", false, false), - schema.SpawnStructField("Child", "Child", false, false), + schema.SpawnStructField("Child", "Link", false, false), }, schema.SpawnStructRepresentationMap(nil), )) + ts.Accumulate(schema.SpawnStruct("TrieLeafNode", []schema.StructField{ schema.SpawnStructField("PartialPath", "Bytes", false, false), diff --git a/trie/marshal.go b/trie/marshal.go index 4ffbc11..9c9c70c 100644 --- a/trie/marshal.go +++ b/trie/marshal.go @@ -211,80 +211,21 @@ func packExtensionNode(node ipld.Node) ([]interface{}, error) { if err != nil { return nil, err } - childLinkNode, err := childNode.LookupByString("Link") - if err == nil { - childLink, err := childLinkNode.AsLink() - if err != nil { - return nil, err - } - childCIDLink, ok := childLink.(cidlink.Link) - if !ok { - return nil, fmt.Errorf("extension node child link needs to be a CID") - } - childMh := childCIDLink.Hash() - decodedChildMh, err := multihash.Decode(childMh) - if err != nil { - return nil, fmt.Errorf("unable to decode Child multihash: %v", err) - } - nodeFields[1] = decodedChildMh.Digest - return nodeFields, nil + childLink, err := childNode.AsLink() + if err != nil { + return nil, err } - childTrieNodeNode, err := childNode.LookupByString("TrieNode") - if err == nil { - // it must be a leaf node as only RLP encodings of storage leaf nodes can be less than 32 bytes in length and stored direclty in a parent node - childLeafNode, err := childTrieNodeNode.LookupByString(LEAF_NODE.String()) - if err != nil { - return nil, fmt.Errorf("only leaf nodes can be less than 32 bytes and stored direclty in a parent node") - } - childLeafNodeFields, err := packLeafNode(childLeafNode) - if err != nil { - return nil, err - } - childLeafNodeRLP, err := rlp.EncodeToBytes(childLeafNodeFields) - if err != nil { - return nil, err - } - nodeFields[1] = childLeafNodeRLP - return nodeFields, nil + childCIDLink, ok := childLink.(cidlink.Link) + if !ok { + return nil, fmt.Errorf("extension node child link needs to be a CID") } - return nil, fmt.Errorf("extension node child needs to be of kind bytes or link") - - /* Child should be a kinded Union, in which case we could do the below type switch instead of map key checking - switch childNode.Kind() { - case ipld.Kind_Link: - childLink, err := childNode.AsLink() - if err != nil { - return nil, err - } - childCIDLink, ok := childLink.(cidlink.Link) - if !ok { - return nil, fmt.Errorf("extension node child link needs to be a CID") - } - childMh := childCIDLink.Hash() - decodedChildMh, err := multihash.Decode(childMh) - if err != nil { - return nil, fmt.Errorf("unable to decode Child multihash: %v", err) - } - nodeFields[1] = decodedChildMh.Digest - case ipld.Kind_Map: // is this possible? Will an extension node ever link to a leaf? In that case it could just be a leaf itself...? - // it must be a leaf node as only RLP encodings of storage leaf nodes can be less than 32 bytes in length and stored direclty in a parent node - childLeafNode, err := childNode.LookupByString(LEAF_NODE.String()) - if err != nil { - return nil, fmt.Errorf("only leaf nodes can be less than 32 bytes and stored direclty in a parent node") - } - childLeafNodeFields, err := packLeafNode(childLeafNode) - if err != nil { - return nil, err - } - childLeafNodeRLP, err := rlp.EncodeToBytes(childLeafNodeFields) - if err != nil { - return nil, err - } - nodeFields[1] = childLeafNodeRLP - default: - return nil, fmt.Errorf("extension node child needs to be of kind bytes or link") + childMh := childCIDLink.Hash() + decodedChildMh, err := multihash.Decode(childMh) + if err != nil { + return nil, fmt.Errorf("unable to decode Child multihash: %v", err) } - */ + nodeFields[1] = decodedChildMh.Digest + return nodeFields, nil } func packLeafNode(node ipld.Node) ([]interface{}, error) { diff --git a/trie/unmarshal.go b/trie/unmarshal.go index 8244f8e..23874f1 100644 --- a/trie/unmarshal.go +++ b/trie/unmarshal.go @@ -118,72 +118,13 @@ func unpackExtensionNode(ma ipld.MapAssembler, nodeFields []interface{}, codec u if err := ma.AssembleKey().AssignString("Child"); err != nil { return err } - childNodeBuilder := dageth.Type.Child.NewBuilder() - childNodeMA, err := childNodeBuilder.BeginMap(1) - if err != nil { - return err - } childLink, ok := nodeFields[1].([]byte) - if ok { - // it's a hash referencing the child node - // make CID link from the bytes - // assign the link value to the MA - childCID := shared.Keccak256ToCid(codec, childLink) - childCIDLink := cidlink.Link{Cid: childCID} - if err := childNodeMA.AssembleKey().AssignString("Link"); err != nil { - return err - } - if err := childNodeMA.AssembleValue().AssignLink(childCIDLink); err != nil { - return err - } - if err := childNodeMA.Finish(); err != nil { - return err - } - return ma.AssembleValue().AssignNode(childNodeBuilder.Build()) - } - // the child node is included directly - // it must be a leaf node, branch and extension will never be less than 32 bytes - childLeaf, ok := nodeFields[1].([]interface{}) if !ok { - return fmt.Errorf("unable to decode branch node entry into []byte or []interface{}") - } - if len(childLeaf) != 2 { - return fmt.Errorf("unexpected number of entries for leaf node; got %d want 2", len(childLeaf)) - } - nodeKind, decodedChildLeaf, err := decodeTwoMemberNode(childLeaf) - if err != nil { - return err - } - if nodeKind != LEAF_NODE { - return fmt.Errorf("child node included directly in branch must be a leaf; got %s", nodeKind.String()) - } - if err := childNodeMA.AssembleKey().AssignString("TrieNode"); err != nil { - return err - } - childTrieNodeMA, err := childNodeMA.AssembleValue().BeginMap(1) - if err != nil { - return err - } - if err := childTrieNodeMA.AssembleKey().AssignString(LEAF_NODE.String()); err != nil { - return err - } - leafNodeMA, err := childTrieNodeMA.AssembleValue().BeginMap(2) - if err != nil { - return err - } - if err := unpackLeafNode(leafNodeMA, decodedChildLeaf, codec); err != nil { - return err - } - if err := leafNodeMA.Finish(); err != nil { - return err - } - if err := childTrieNodeMA.Finish(); err != nil { - return err - } - if err := childNodeMA.Finish(); err != nil { - return err + return fmt.Errorf("unable to assert second member of extension node to type `[]byte`") } - return ma.AssembleValue().AssignNode(childNodeBuilder.Build()) + childCID := shared.Keccak256ToCid(codec, childLink) + childCIDLink := cidlink.Link{Cid: childCID} + return ma.AssembleValue().AssignLink(childCIDLink) } func unpackBranchNode(ma ipld.MapAssembler, nodeFields []interface{}, codec uint64) error { From 83eab1289faff72b448f48dccaa81502f1a62b86 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 3 Aug 2021 11:55:22 -0500 Subject: [PATCH 02/11] updates to gen.go for merkelizing logs in IPLD representation of Receipt --- gen.go | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/gen.go b/gen.go index a64af00..9906103 100644 --- a/gen.go +++ b/gen.go @@ -63,9 +63,9 @@ func accumulateChainTypes(ts *schema.TypeSystem) { ParentCID &Header UnclesCID &Uncles Coinbase Address - StateRootCID &StateTrieNode - TxRootCID &TxTrieNode - RctRootCID &RctTrieNode + StateRootCID &TrieNode + TxRootCID &TrieNode + RctRootCID &TrieNode Bloom Bloom Difficulty BigInt Number BigInt @@ -174,9 +174,18 @@ func accumulateChainTypes(ts *schema.TypeSystem) { Topics Topics Data Bytes } + */ + ts.Accumulate(schema.SpawnList("Topics", "Hash", false)) + ts.Accumulate(schema.SpawnStruct("Log", + []schema.StructField{ + schema.SpawnStructField("Address", "Address", false, false), + schema.SpawnStructField("Topics", "Topics", false, false), + schema.SpawnStructField("Data", "Bytes", false, false), + }, + schema.SpawnStructRepresentationMap(nil), + )) - type Logs [Log] - + /* type Receipt struct { TxType TxType // We could make Status an enum @@ -184,21 +193,11 @@ func accumulateChainTypes(ts *schema.TypeSystem) { PostState Hash // nullable CumulativeGasUsed Uint Bloom Bloom - Logs Logs + LogRootCID &TrieNode } type Receipts [Receipt] */ - ts.Accumulate(schema.SpawnList("Topics", "Hash", false)) - ts.Accumulate(schema.SpawnStruct("Log", - []schema.StructField{ - schema.SpawnStructField("Address", "Address", false, false), - schema.SpawnStructField("Topics", "Topics", false, false), - schema.SpawnStructField("Data", "Bytes", false, false), - }, - schema.SpawnStructRepresentationMap(nil), - )) - ts.Accumulate(schema.SpawnList("Logs", "Log", false)) ts.Accumulate(schema.SpawnStruct("Receipt", []schema.StructField{ schema.SpawnStructField("TxType", "TxType", false, false), @@ -206,7 +205,7 @@ func accumulateChainTypes(ts *schema.TypeSystem) { schema.SpawnStructField("Status", "Uint", false, true), schema.SpawnStructField("CumulativeGasUsed", "Uint", false, false), schema.SpawnStructField("Bloom", "Bloom", false, false), - schema.SpawnStructField("Logs", "Logs", false, false), + schema.SpawnStructField("LogRootCID", "Link", false, false), }, schema.SpawnStructRepresentationMap(nil), )) @@ -349,7 +348,7 @@ func accumulateStateDataStructures(ts *schema.TypeSystem) { type Account struct { Nonce Uint Balance Balance - StorageRootCID &StorageTrieNode + StorageRootCID &TrieNode CodeCID &ByteCode } */ From 5ccd005d1695eea08f7f2bfbb68f8923f9b5945d Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 3 Aug 2021 11:56:35 -0500 Subject: [PATCH 03/11] log IPLD marshaller and unmarshaller --- log/marshal.go | 115 ++++++++++++++++++++++++++++++++++++++++++++++ log/multicodec.go | 55 ++++++++++++++++++++++ log/unmarshal.go | 90 ++++++++++++++++++++++++++++++++++++ 3 files changed, 260 insertions(+) create mode 100644 log/marshal.go create mode 100644 log/multicodec.go create mode 100644 log/unmarshal.go diff --git a/log/marshal.go b/log/marshal.go new file mode 100644 index 0000000..435e39f --- /dev/null +++ b/log/marshal.go @@ -0,0 +1,115 @@ +package rct + +import ( + "fmt" + "io" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/rlp" + "github.com/ipld/go-ipld-prime" + + dageth "github.com/vulcanize/go-codec-dageth" + "github.com/vulcanize/go-codec-dageth/shared" +) + +// Encode provides an IPLD codec encode interface for eth log IPLDs. +// This function is registered via the go-ipld-prime link loader for multicodec +// code TBD when this package is invoked via init. +func Encode(node ipld.Node, w io.Writer) error { + // 1KiB can be allocated on the stack, and covers most small nodes + // without having to grow the buffer and cause allocations. + enc := make([]byte, 0, 1024) + + enc, err := AppendEncode(enc, node) + if err != nil { + return err + } + _, err = w.Write(enc) + return err +} + +// AppendEncode is like Encode, but it uses a destination buffer directly. +// This means less copying of bytes, and if the destination has enough capacity, +// fewer allocations. +func AppendEncode(enc []byte, inNode ipld.Node) ([]byte, error) { + log := new(types.Log) + if err := EncodeLog(log, inNode); err != nil { + return nil, err + } + wbs := shared.NewWriteableByteSlice(&enc) + if err := rlp.Encode(wbs, log); err != nil { + return nil, err + } + return enc, nil +} + +// EncodeLog packs the node into the go-ethereum Log +func EncodeLog(log *types.Log, inNode ipld.Node) error { + // Wrap in a typed node for some basic schema form checking + builder := dageth.Type.Log.NewBuilder() + if err := builder.AssignNode(inNode); err != nil { + return err + } + node := builder.Build() + for _, pFunc := range requiredPackFuncs { + if err := pFunc(log, node); err != nil { + return fmt.Errorf("invalid DAG-ETH Log form (%v)", err) + } + } + return nil +} + +var requiredPackFuncs = []func(*types.Log, ipld.Node) error{ + packAddress, + packTopics, + packData, +} + +func packAddress(log *types.Log, node ipld.Node) error { + addrNode, err := node.LookupByString("Address") + if err != nil { + return fmt.Errorf("receipt log is missing an Address node: %v", err) + } + addrBytes, err := addrNode.AsBytes() + if err != nil { + return err + } + log.Address = common.BytesToAddress(addrBytes) + return nil +} + +func packTopics(log *types.Log, node ipld.Node) error { + topicsNode, err := node.LookupByString("Topics") + if err != nil { + return fmt.Errorf("receipt log is missing a Topics node: %v", err) + } + topics := make([]common.Hash, topicsNode.Length()) + topicsIt := topicsNode.ListIterator() + for !topicsIt.Done() { + topicIndex, topicNode, err := topicsIt.Next() + if err != nil { + return err + } + topicBytes, err := topicNode.AsBytes() + if err != nil { + return err + } + topics[topicIndex] = common.BytesToHash(topicBytes) + } + log.Topics = topics + return nil +} + +func packData(log *types.Log, node ipld.Node) error { + dataNode, err := node.LookupByString("Data") + if err != nil { + return fmt.Errorf("receipt log is missing a Data node: %v", err) + } + data, err := dataNode.AsBytes() + if err != nil { + return err + } + log.Data = data + return nil +} diff --git a/log/multicodec.go b/log/multicodec.go new file mode 100644 index 0000000..45689a7 --- /dev/null +++ b/log/multicodec.go @@ -0,0 +1,55 @@ +package rct + +import ( + "io" + + "github.com/ipfs/go-cid" + "github.com/ipld/go-ipld-prime" + cidlink "github.com/ipld/go-ipld-prime/linking/cid" + "github.com/ipld/go-ipld-prime/multicodec" + "github.com/ipld/go-ipld-prime/traversal" + "github.com/multiformats/go-multihash" + + dageth "github.com/vulcanize/go-codec-dageth" +) + +var ( + _ ipld.Decoder = Decode + _ ipld.Encoder = Encode + + MultiCodecType = uint64(cid.EthTxReceipt) // TBD + MultiHashType = uint64(multihash.KECCAK_256) +) + +func init() { + multicodec.RegisterDecoder(MultiCodecType, Decode) + multicodec.RegisterEncoder(MultiCodecType, Encode) +} + +// AddSupportToChooser takes an existing node prototype chooser and subs in +// Log for the eth log multicodec code. +func AddSupportToChooser(existing traversal.LinkTargetNodePrototypeChooser) traversal.LinkTargetNodePrototypeChooser { + return func(lnk ipld.Link, lnkCtx ipld.LinkContext) (ipld.NodePrototype, error) { + if lnk, ok := lnk.(cidlink.Link); ok && lnk.Cid.Prefix().Codec == MultiCodecType { + return dageth.Type.Log, nil + } + return existing(lnk, lnkCtx) + } +} + +// We switched to simpler API names after v1.0.0, so keep the old names around +// as deprecated forwarding funcs until a future v2+. +// TODO: consider deprecating Marshal/Unmarshal too, since it's a bit +// unnecessary to have two supported names for each API. + +// Deprecated: use Decode instead. +func Decoder(na ipld.NodeAssembler, r io.Reader) error { return Decode(na, r) } + +// Deprecated: use Decode instead. +func Unmarshal(na ipld.NodeAssembler, r io.Reader) error { return Decode(na, r) } + +// Deprecated: use Encode instead. +func Encoder(inNode ipld.Node, w io.Writer) error { return Encode(inNode, w) } + +// Deprecated: use Encode instead. +func Marshal(inNode ipld.Node, w io.Writer) error { return Encode(inNode, w) } diff --git a/log/unmarshal.go b/log/unmarshal.go new file mode 100644 index 0000000..a5f5860 --- /dev/null +++ b/log/unmarshal.go @@ -0,0 +1,90 @@ +package rct + +import ( + "fmt" + "io" + "io/ioutil" + + "github.com/ethereum/go-ethereum/rlp" + + "github.com/ethereum/go-ethereum/core/types" + "github.com/ipld/go-ipld-prime" +) + +// Decode provides an IPLD codec decode interface for eth log IPLDs. +// This function is registered via the go-ipld-prime link loader for multicodec +// code TBD when this package is invoked via init. +func Decode(na ipld.NodeAssembler, in io.Reader) error { + var src []byte + if buf, ok := in.(interface{ Bytes() []byte }); ok { + src = buf.Bytes() + } else { + var err error + src, err = ioutil.ReadAll(in) + if err != nil { + return err + } + } + return DecodeBytes(na, src) +} + +// DecodeBytes is like Decode, but it uses an input buffer directly. +// Decode will grab or read all the bytes from an io.Reader anyway, so this can +// save having to copy the bytes or create a bytes.Buffer. +func DecodeBytes(na ipld.NodeAssembler, src []byte) error { + var log types.Log + if err := rlp.DecodeBytes(src, log); err != nil { + return err + } + return DecodeLog(na, log) +} + +// DecodeLog unpacks a go-ethereum Log into the NodeAssembler +func DecodeLog(na ipld.NodeAssembler, log types.Log) error { + ma, err := na.BeginMap(3) + if err != nil { + return err + } + for _, upFunc := range requiredUnpackFuncs { + if err := upFunc(ma, log); err != nil { + return fmt.Errorf("invalid DAG-ETH Log binary (%v)", err) + } + } + return ma.Finish() +} + +var requiredUnpackFuncs = []func(ipld.MapAssembler, types.Log) error{ + unpackAddress, + unpackTopics, + unpackData, +} + +func unpackAddress(ma ipld.MapAssembler, log types.Log) error { + if err := ma.AssembleKey().AssignString("Address"); err != nil { + return err + } + return ma.AssembleValue().AssignBytes(log.Address.Bytes()) +} + +func unpackTopics(ma ipld.MapAssembler, log types.Log) error { + if err := ma.AssembleKey().AssignString("Topics"); err != nil { + return err + } + topicsLa, err := ma.AssembleValue().BeginList(int64(len(log.Topics))) + if err != nil { + return err + } + for _, topic := range log.Topics { + if err := topicsLa.AssembleValue().AssignBytes(topic.Bytes()); err != nil { + return err + } + } + return topicsLa.Finish() +} + +func unpackData(ma ipld.MapAssembler, log types.Log) error { + if err := ma.AssembleKey().AssignString("Data"); err != nil { + return err + } + return ma.AssembleValue().AssignBytes(log.Data) +} From 5c34ca4e2b756cf04a982e2014a8a76f4705822f Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 3 Aug 2021 11:58:39 -0500 Subject: [PATCH 04/11] log trie codec --- log/marshal.go | 2 +- log/multicodec.go | 5 ++-- log/unmarshal.go | 2 +- log_trie/marshal.go | 25 +++++++++++++++++++ log_trie/multicodec.go | 55 ++++++++++++++++++++++++++++++++++++++++++ log_trie/unmarshal.go | 25 +++++++++++++++++++ trie/marshal.go | 1 + trie/unmarshal.go | 19 ++++++++++----- 8 files changed, 123 insertions(+), 11 deletions(-) create mode 100644 log_trie/marshal.go create mode 100644 log_trie/multicodec.go create mode 100644 log_trie/unmarshal.go diff --git a/log/marshal.go b/log/marshal.go index 435e39f..01abdd0 100644 --- a/log/marshal.go +++ b/log/marshal.go @@ -1,4 +1,4 @@ -package rct +package log import ( "fmt" diff --git a/log/multicodec.go b/log/multicodec.go index 45689a7..320172c 100644 --- a/log/multicodec.go +++ b/log/multicodec.go @@ -1,9 +1,8 @@ -package rct +package log import ( "io" - "github.com/ipfs/go-cid" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" "github.com/ipld/go-ipld-prime/multicodec" @@ -17,7 +16,7 @@ var ( _ ipld.Decoder = Decode _ ipld.Encoder = Encode - MultiCodecType = uint64(cid.EthTxReceipt) // TBD + MultiCodecType = uint64(0x9000) // TBD MultiHashType = uint64(multihash.KECCAK_256) ) diff --git a/log/unmarshal.go b/log/unmarshal.go index a5f5860..aacfb77 100644 --- a/log/unmarshal.go +++ b/log/unmarshal.go @@ -1,4 +1,4 @@ -package rct +package log import ( "fmt" diff --git a/log_trie/marshal.go b/log_trie/marshal.go new file mode 100644 index 0000000..8dd5189 --- /dev/null +++ b/log_trie/marshal.go @@ -0,0 +1,25 @@ +package log_trie + +import ( + "io" + + "github.com/ipld/go-ipld-prime" + + dageth_trie "github.com/vulcanize/go-codec-dageth/trie" +) + +// Encode provides an IPLD codec encode interface for eth log trie node IPLDs. +// This function is registered via the go-ipld-prime link loader for multicodec +// code 0x94 when this package is invoked via init. +// This is a pure wrapping around dageth_trie.Encode to expose it from this package +func Encode(node ipld.Node, w io.Writer) error { + return dageth_trie.Encode(node, w) +} + +// AppendEncode is like Encode, but it uses a destination buffer directly. +// This means less copying of bytes, and if the destination has enough capacity, +// fewer allocations. +// This is a pure wrapping around dageth_trie.AppendEncode to expose it from this package +func AppendEncode(enc []byte, inNode ipld.Node) ([]byte, error) { + return dageth_trie.AppendEncode(enc, inNode) +} diff --git a/log_trie/multicodec.go b/log_trie/multicodec.go new file mode 100644 index 0000000..f77b2b2 --- /dev/null +++ b/log_trie/multicodec.go @@ -0,0 +1,55 @@ +package log_trie + +import ( + "io" + + "github.com/ipfs/go-cid" + "github.com/ipld/go-ipld-prime" + cidlink "github.com/ipld/go-ipld-prime/linking/cid" + "github.com/ipld/go-ipld-prime/multicodec" + "github.com/ipld/go-ipld-prime/traversal" + "github.com/multiformats/go-multihash" + + dageth "github.com/vulcanize/go-codec-dageth" +) + +var ( + _ ipld.Decoder = Decode + _ ipld.Encoder = Encode + + MultiCodecType = uint64(cid.EthTxReceiptTrie) // TBD + MultiHashType = uint64(multihash.KECCAK_256) +) + +func init() { + multicodec.RegisterDecoder(MultiCodecType, Decode) + multicodec.RegisterEncoder(MultiCodecType, Encode) +} + +// AddSupportToChooser takes an existing node prototype chooser and subs in +// TrieNode for the eth log trie multicodec code. +func AddSupportToChooser(existing traversal.LinkTargetNodePrototypeChooser) traversal.LinkTargetNodePrototypeChooser { + return func(lnk ipld.Link, lnkCtx ipld.LinkContext) (ipld.NodePrototype, error) { + if lnk, ok := lnk.(cidlink.Link); ok && lnk.Cid.Prefix().Codec == MultiCodecType { + return dageth.Type.TrieNode, nil + } + return existing(lnk, lnkCtx) + } +} + +// We switched to simpler API names after v1.0.0, so keep the old names around +// as deprecated forwarding funcs until a future v2+. +// TODO: consider deprecating Marshal/Unmarshal too, since it's a bit +// unnecessary to have two supported names for each API. + +// Deprecated: use Decode instead. +func Decoder(na ipld.NodeAssembler, r io.Reader) error { return Decode(na, r) } + +// Deprecated: use Decode instead. +func Unmarshal(na ipld.NodeAssembler, r io.Reader) error { return Decode(na, r) } + +// Deprecated: use Encode instead. +func Encoder(inNode ipld.Node, w io.Writer) error { return Encode(inNode, w) } + +// Deprecated: use Encode instead. +func Marshal(inNode ipld.Node, w io.Writer) error { return Encode(inNode, w) } diff --git a/log_trie/unmarshal.go b/log_trie/unmarshal.go new file mode 100644 index 0000000..f672e1d --- /dev/null +++ b/log_trie/unmarshal.go @@ -0,0 +1,25 @@ +package log_trie + +import ( + "io" + + "github.com/ipld/go-ipld-prime" + + dageth_trie "github.com/vulcanize/go-codec-dageth/trie" +) + +// Decode provides an IPLD codec decode interface for eth log trie node IPLDs. +// This function is registered via the go-ipld-prime link loader for multicodec +// code 0x94 when this package is invoked via init. +// This simply wraps dageth_trie.DecodeTrieNode with the proper multicodec type +func Decode(na ipld.NodeAssembler, in io.Reader) error { + return dageth_trie.DecodeTrieNode(na, in, MultiCodecType) +} + +// DecodeBytes is like Decode, but it uses an input buffer directly. +// Decode will grab or read all the bytes from an io.Reader anyway, so this can +// save having to copy the bytes or create a bytes.Buffer. +// This simply wraps dageth_trie.DecodeTrieNodeBytes with the proper multicodec type +func DecodeBytes(na ipld.NodeAssembler, src []byte) error { + return dageth_trie.DecodeTrieNodeBytes(na, src, MultiCodecType) +} diff --git a/trie/marshal.go b/trie/marshal.go index 9c9c70c..e84d0c5 100644 --- a/trie/marshal.go +++ b/trie/marshal.go @@ -33,6 +33,7 @@ const ( RCT_VALUE ValueKind = "Receipt" STATE_VALUE ValueKind = "Account" STORAGE_VALUE ValueKind = "Bytes" + LOG_VALUE ValueKind = "Log" ) func (n NodeKind) String() string { diff --git a/trie/unmarshal.go b/trie/unmarshal.go index 23874f1..df279e0 100644 --- a/trie/unmarshal.go +++ b/trie/unmarshal.go @@ -7,6 +7,8 @@ import ( "strconv" "strings" + "github.com/vulcanize/go-codec-dageth/log" + dageth "github.com/vulcanize/go-codec-dageth" "github.com/vulcanize/go-codec-dageth/shared" @@ -14,9 +16,9 @@ import ( "github.com/ipfs/go-cid" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" - dageth_rct "github.com/vulcanize/go-codec-dageth/rct" - dageth_account "github.com/vulcanize/go-codec-dageth/state_account" - dageth_tx "github.com/vulcanize/go-codec-dageth/tx" + "github.com/vulcanize/go-codec-dageth/rct" + "github.com/vulcanize/go-codec-dageth/state_account" + "github.com/vulcanize/go-codec-dageth/tx" ) // DecodeTrieNode provides an IPLD codec decode interface for eth merkle patricia trie nodes @@ -268,22 +270,27 @@ func unpackValue(ma ipld.MapAssembler, val []byte, codec uint64) error { if err := ma.AssembleKey().AssignString(TX_VALUE.String()); err != nil { return err } - return dageth_tx.DecodeBytes(ma.AssembleValue(), val) + return tx.DecodeBytes(ma.AssembleValue(), val) case cid.EthTxReceiptTrie: if err := ma.AssembleKey().AssignString(RCT_VALUE.String()); err != nil { return err } - return dageth_rct.DecodeBytes(ma.AssembleValue(), val) + return rct.DecodeBytes(ma.AssembleValue(), val) case cid.EthStateTrie: if err := ma.AssembleKey().AssignString(STATE_VALUE.String()); err != nil { return err } - return dageth_account.DecodeBytes(ma.AssembleValue(), val) + return account.DecodeBytes(ma.AssembleValue(), val) case cid.EthStorageTrie: if err := ma.AssembleKey().AssignString(STORAGE_VALUE.String()); err != nil { return err } return ma.AssembleValue().AssignBytes(val) + case log.MultiCodecType: + if err := ma.AssembleKey().AssignString(LOG_VALUE.String()); err != nil { + return err + } + return log.DecodeBytes(ma.AssembleValue(), val) default: return fmt.Errorf("unsupported multicodec type (%d) for eth TrieNode unmarshaller", codec) } From ede2453324171fc4dbe0a890c80a6468b9ba4ed3 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 3 Aug 2021 12:42:27 -0500 Subject: [PATCH 05/11] need to keep the list of logs materialized in the receipt IPLD object so that when we encode it we don't need a LinkSystem/BlockReadOpener to iterte over the linked LogTrie and collect the logs for packing into the receipt consensus encoding --- gen.go | 5 +++ rct/unmarshal.go | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/gen.go b/gen.go index 9906103..9aa9941 100644 --- a/gen.go +++ b/gen.go @@ -174,6 +174,8 @@ func accumulateChainTypes(ts *schema.TypeSystem) { Topics Topics Data Bytes } + + type Logs [Log] */ ts.Accumulate(schema.SpawnList("Topics", "Hash", false)) ts.Accumulate(schema.SpawnStruct("Log", @@ -184,6 +186,7 @@ func accumulateChainTypes(ts *schema.TypeSystem) { }, schema.SpawnStructRepresentationMap(nil), )) + ts.Accumulate(schema.SpawnList("Logs", "Log", false)) /* type Receipt struct { @@ -193,6 +196,7 @@ func accumulateChainTypes(ts *schema.TypeSystem) { PostState Hash // nullable CumulativeGasUsed Uint Bloom Bloom + Logs Logs LogRootCID &TrieNode } @@ -205,6 +209,7 @@ func accumulateChainTypes(ts *schema.TypeSystem) { schema.SpawnStructField("Status", "Uint", false, true), schema.SpawnStructField("CumulativeGasUsed", "Uint", false, false), schema.SpawnStructField("Bloom", "Bloom", false, false), + schema.SpawnStructField("Logs", "Logs", false, false), schema.SpawnStructField("LogRootCID", "Link", false, false), }, schema.SpawnStructRepresentationMap(nil), diff --git a/rct/unmarshal.go b/rct/unmarshal.go index cc98dcd..3346bc7 100644 --- a/rct/unmarshal.go +++ b/rct/unmarshal.go @@ -6,6 +6,16 @@ import ( "io" "io/ioutil" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/rawdb" + "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/rlp" + "github.com/ethereum/go-ethereum/trie" + "github.com/ipfs/go-cid" + cidlink "github.com/ipld/go-ipld-prime/linking/cid" + "github.com/multiformats/go-multihash" + "github.com/vulcanize/go-codec-dageth/log" + "github.com/ethereum/go-ethereum/core/types" "github.com/ipld/go-ipld-prime" ) @@ -58,6 +68,7 @@ var requiredUnpackFuncs = []func(ipld.MapAssembler, types.Receipt) error{ unpackCumulativeGasUsed, unpackBloom, unpackLogs, + unpackLogRootCID, } func unpackTxType(ma ipld.MapAssembler, rct types.Receipt) error { @@ -164,3 +175,74 @@ func unpackLogs(ma ipld.MapAssembler, rct types.Receipt) error { } return la.Finish() } + +func unpackLogRootCID(ma ipld.MapAssembler, rct types.Receipt) error { + logTrieRoot, err := processLogs(rct.Logs) + if err != nil { + return err + } + logMh, err := multihash.Encode(logTrieRoot, log.MultiHashType) + if err != nil { + return err + } + logCID := cid.NewCidV1(log.MultiCodecType, logMh) + logLinkCID := cidlink.Link{Cid: logCID} + if err := ma.AssembleKey().AssignString("LogRootCID"); err != nil { + return err + } + return ma.AssembleValue().AssignLink(logLinkCID) +} + +// processLogs takes the logs in a receipt and +// creates a new log trie out of them, returning the root hash +func processLogs(logs []*types.Log) ([]byte, error) { + lTrie := newlocalTrie() + + for idx, l := range logs { + logRLP, err := rlp.EncodeToBytes(l) + if err != nil { + return nil, err + } + if err := lTrie.add(idx, logRLP); err != nil { + return nil, err + } + } + return lTrie.rootHash(), nil +} + +// localTrie wraps a go-ethereum trie and its underlying memory db. +// It contributes to the creation of the trie node objects. +type localTrie struct { + DB ethdb.Database + trieDB *trie.Database + trie *trie.Trie +} + +// newlocalTrie initializes and returns a localTrie object +func newlocalTrie() *localTrie { + var err error + lt := &localTrie{} + lt.DB = rawdb.NewMemoryDatabase() + lt.trieDB = trie.NewDatabase(lt.DB) + lt.trie, err = trie.New(common.Hash{}, lt.trieDB) + if err != nil { + panic(err) + } + return lt +} + +// add receives the index of an object and its rawdata value +// and includes it into the localTrie +func (lt *localTrie) add(idx int, rawdata []byte) error { + key, err := rlp.EncodeToBytes(uint(idx)) + if err != nil { + panic(err) + } + return lt.trie.TryUpdate(key, rawdata) +} + +// rootHash returns the computed trie root. +// Useful for sanity checks on parsed data. +func (lt *localTrie) rootHash() []byte { + return lt.trie.Hash().Bytes() +} From c7d7c0c95bf2ba5024dc46a3751990119adddbf7 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 3 Aug 2021 21:56:47 -0500 Subject: [PATCH 06/11] proposed multicodec types --- log/log_test.go | 330 ++++++++++++++++++++ log/multicodec.go | 2 +- log/unmarshal.go | 2 +- log_trie/log_trie_test.go | 622 ++++++++++++++++++++++++++++++++++++++ log_trie/multicodec.go | 3 +- log_trie/unmarshal.go | 2 +- 6 files changed, 956 insertions(+), 5 deletions(-) create mode 100644 log/log_test.go create mode 100644 log_trie/log_trie_test.go diff --git a/log/log_test.go b/log/log_test.go new file mode 100644 index 0000000..f426a1e --- /dev/null +++ b/log/log_test.go @@ -0,0 +1,330 @@ +package log_test + +import ( + "bytes" + "encoding/binary" + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ipld/go-ipld-prime" + + dageth "github.com/vulcanize/go-codec-dageth" + "github.com/vulcanize/go-codec-dageth/rct" +) + +var ( + mockHash = crypto.Keccak256([]byte{1, 2, 3, 4, 5}) + legacyReceipt = &types.Receipt{ + Status: types.ReceiptStatusSuccessful, + CumulativeGasUsed: 1, + Logs: []*types.Log{ + { + Address: common.BytesToAddress([]byte{0x11}), + Topics: []common.Hash{common.HexToHash("hello"), common.HexToHash("world")}, + Data: []byte{0x01, 0x00, 0xff}, + }, + { + Address: common.BytesToAddress([]byte{0x01, 0x11}), + Topics: []common.Hash{common.HexToHash("goodbye"), common.HexToHash("world")}, + Data: []byte{0x01, 0x00, 0xff}, + }, + }, + Type: types.LegacyTxType, + } + accessListReceipt = &types.Receipt{ + PostState: mockHash, + CumulativeGasUsed: 1, + Logs: []*types.Log{ + { + Address: common.BytesToAddress([]byte{0x11}), + Topics: []common.Hash{common.HexToHash("hello"), common.HexToHash("world")}, + Data: []byte{0x01, 0x00, 0xff}, + }, + { + Address: common.BytesToAddress([]byte{0x01, 0x11}), + Topics: []common.Hash{common.HexToHash("goodbye"), common.HexToHash("world")}, + Data: []byte{0x01, 0x00, 0xff}, + }, + }, + Type: types.AccessListTxType, + } + dynamicFeeReceipt = &types.Receipt{ + Status: types.ReceiptStatusSuccessful, + CumulativeGasUsed: 1, + Logs: []*types.Log{ + { + Address: common.BytesToAddress([]byte{0x11}), + Topics: []common.Hash{common.HexToHash("hello"), common.HexToHash("world")}, + Data: []byte{0x01, 0x00, 0xff}, + }, + { + Address: common.BytesToAddress([]byte{0x01, 0x11}), + Topics: []common.Hash{common.HexToHash("goodbye"), common.HexToHash("world")}, + Data: []byte{0x01, 0x00, 0xff}, + }, + }, + Type: types.DynamicFeeTxType, + } + + lReceiptConsensusEnc, alReceiptConsensusEnc, dfReceiptConsensusEnc []byte + legacyReceiptNode, accessListReceiptNode, dynamicFeeReceiptNode ipld.Node +) + +/* IPLD Schemas +type Topics [Hash] + +type Log struct { + Address Address + Topics Topics + Data Bytes +} + +type Logs [Log] + +type Receipt struct { + TxType TxType + Status nullable Uint + PostState nullable Hash + CumulativeGasUsed Uint + Bloom Bloom + Logs Logs +} + +type Receipts [Receipt] +*/ + +func TestReceiptCodec(t *testing.T) { + var err error + lReceiptConsensusEnc, err = legacyReceipt.MarshalBinary() + if err != nil { + t.Fatalf("unable to marshal legacy receipt binary: %v", err) + } + alReceiptConsensusEnc, err = accessListReceipt.MarshalBinary() + if err != nil { + t.Fatalf("unable to marshal access list receipt binary: %v", err) + } + testReceiptDecoding(t) + testAccessListReceiptNodeContents(t) + testLegacyReceiptNodeContents(t) + testReceiptEncoding(t) +} + +func testReceiptDecoding(t *testing.T) { + legacyRctBuilder := dageth.Type.Receipt.NewBuilder() + legacyRctReader := bytes.NewReader(lReceiptConsensusEnc) + if err := rct.Decode(legacyRctBuilder, legacyRctReader); err != nil { + t.Fatalf("unable to decode legacy receipt into an IPLD node: %v", err) + } + legacyReceiptNode = legacyRctBuilder.Build() + + alRctBuilder := dageth.Type.Receipt.NewBuilder() + alRctReader := bytes.NewReader(alReceiptConsensusEnc) + if err := rct.Decode(alRctBuilder, alRctReader); err != nil { + t.Fatalf("unable to decode access list receipt into an IPLD node: %v", err) + } + accessListReceiptNode = alRctBuilder.Build() +} + +func testAccessListReceiptNodeContents(t *testing.T) { + verifySharedContent(t, accessListReceiptNode, accessListReceipt) + statusNode, err := accessListReceiptNode.LookupByString("Status") + if err != nil { + t.Fatalf("receipt is missing Status: %v", err) + } + if !statusNode.IsNull() { + t.Fatalf("receipt Status should be null") + } + + postStateNode, err := accessListReceiptNode.LookupByString("PostState") + if err != nil { + t.Fatalf("receipt is missing PostState: %v", err) + } + if postStateNode.IsNull() { + t.Errorf("receipt PostState should not be null") + } + postStateBy, err := postStateNode.AsBytes() + if err != nil { + t.Fatalf("receipt PostState should be of type Bytes: %v", err) + } + if !bytes.Equal(postStateBy, accessListReceipt.PostState) { + t.Errorf("receipt post state (%d) does not match expected post state (%d)", postStateBy, accessListReceipt.PostState) + } +} + +func testDynamicFeeReceiptNodeContents(t *testing.T) { + verifySharedContent(t, dynamicFeeReceiptNode, dynamicFeeReceipt) + statusNode, err := dynamicFeeReceiptNode.LookupByString("Status") + if err != nil { + t.Fatalf("receipt is missing Status: %v", err) + } + if statusNode.IsNull() { + t.Fatalf("receipt Status should not be null") + } + statusBy, err := statusNode.AsBytes() + if err != nil { + t.Fatalf("receipt Status should be of type Bytes: %v", err) + } + status := binary.BigEndian.Uint64(statusBy) + if status != dynamicFeeReceipt.Status { + t.Errorf("receipt status (%d) does not match expected status (%d)", status, dynamicFeeReceipt.Status) + } + + postStateNode, err := dynamicFeeReceiptNode.LookupByString("PostState") + if err != nil { + t.Fatalf("receipt is missing PostState: %v", err) + } + if !postStateNode.IsNull() { + t.Errorf("receipt PostState should be null") + } +} + +func testLegacyReceiptNodeContents(t *testing.T) { + verifySharedContent(t, legacyReceiptNode, legacyReceipt) + statusNode, err := legacyReceiptNode.LookupByString("Status") + if err != nil { + t.Fatalf("receipt is missing Status: %v", err) + } + if statusNode.IsNull() { + t.Fatalf("receipt Status should not be null") + } + statusBy, err := statusNode.AsBytes() + if err != nil { + t.Fatalf("receipt Status should be of type Bytes: %v", err) + } + status := binary.BigEndian.Uint64(statusBy) + if status != legacyReceipt.Status { + t.Errorf("receipt status (%d) does not match expected status (%d)", status, legacyReceipt.Status) + } + + postStateNode, err := legacyReceiptNode.LookupByString("PostState") + if err != nil { + t.Fatalf("receipt is missing PostState: %v", err) + } + if !postStateNode.IsNull() { + t.Errorf("receipt PostState should be null") + } +} + +func verifySharedContent(t *testing.T, rctNode ipld.Node, rct *types.Receipt) { + typeNode, err := rctNode.LookupByString("TxType") + if err != nil { + t.Fatalf("receipt is missing TxType: %v", err) + } + typeBy, err := typeNode.AsBytes() + if err != nil { + t.Fatalf("receipt TxType should be of type Bytes: %v", err) + } + if len(typeBy) != 1 { + t.Fatalf("receipt TxType should be a single byte") + } + if typeBy[0] != rct.Type { + t.Errorf("receipt tx type (%d) does not match expected tx type (%d)", typeBy[0], rct.Type) + } + + cguNode, err := rctNode.LookupByString("CumulativeGasUsed") + if err != nil { + t.Fatalf("receipt is missing CumulativeGasUsed: %v", err) + } + cguBy, err := cguNode.AsBytes() + if err != nil { + t.Fatalf("receipt CumulativeGasUsed should be of type Bytes: %v", err) + } + cgu := binary.BigEndian.Uint64(cguBy) + if cgu != rct.CumulativeGasUsed { + t.Errorf("receipt cumulative gas used (%d) does not match expected cumulative gas used (%d)", cgu, rct.CumulativeGasUsed) + } + + bloomNode, err := rctNode.LookupByString("Bloom") + if err != nil { + t.Fatalf("receipt is missing Bloom: %v", err) + } + bloomBy, err := bloomNode.AsBytes() + if err != nil { + t.Fatalf("receipt Bloom should be of type Bytes: %v", err) + } + if !bytes.Equal(bloomBy, rct.Bloom.Bytes()) { + t.Errorf("receipt bloom (%x) does not match expected bloom (%x)", bloomBy, rct.Bloom.Bytes()) + } + + logsNode, err := rctNode.LookupByString("Logs") + if err != nil { + t.Fatalf("receipt is missing Logs: %v", err) + } + if logsNode.Length() != int64(len(rct.Logs)) { + t.Fatalf("receipt should have %d logs", len(rct.Logs)) + } + logsLI := logsNode.ListIterator() + for !logsLI.Done() { + i, logNode, err := logsLI.Next() + if err != nil { + t.Fatalf("receipt log iterator error: %v", err) + } + currentLog := rct.Logs[i] + addrNode, err := logNode.LookupByString("Address") + if err != nil { + t.Fatalf("receipt log is missing Address: %v", err) + } + addrBy, err := addrNode.AsBytes() + if err != nil { + t.Fatalf("receipt log Address should be of type Bytes: %v", err) + } + if !bytes.Equal(addrBy, currentLog.Address.Bytes()) { + t.Errorf("receipt log address (%x) does not match expected address (%x)", addrBy, currentLog.Address.Bytes()) + } + dataNode, err := logNode.LookupByString("Data") + if err != nil { + t.Fatalf("receipt log is missing Data: %v", err) + } + data, err := dataNode.AsBytes() + if err != nil { + t.Fatalf("receipt log Data should be of type Bytes: %v", err) + } + if !bytes.Equal(data, currentLog.Data) { + t.Errorf("receipt log data (%x) does not match expected data (%x)", data, currentLog.Data) + } + topicsNode, err := logNode.LookupByString("Topics") + if err != nil { + t.Fatalf("receipt log is missing Topics: %v", err) + } + if topicsNode.Length() != 2 { + t.Fatal("receipt log should have two topics") + } + topicsLI := topicsNode.ListIterator() + for !topicsLI.Done() { + j, topicNode, err := topicsLI.Next() + if err != nil { + t.Fatalf("receipt log topic iterator error: %v", err) + } + currentTopic := currentLog.Topics[j].Bytes() + topicBy, err := topicNode.AsBytes() + if err != nil { + t.Fatalf("receipt log Topic should be of type Bytes: %v", err) + } + if !bytes.Equal(topicBy, currentTopic) { + t.Errorf("receipt log topic%d bytes (%x) does not match expected bytes (%x)", j, topicBy, currentTopic) + } + } + } +} + +func testReceiptEncoding(t *testing.T) { + legRctWriter := new(bytes.Buffer) + if err := rct.Encode(legacyReceiptNode, legRctWriter); err != nil { + t.Fatalf("unable to encode legacy receipt into writer: %v", err) + } + legRctBytes := legRctWriter.Bytes() + if !bytes.Equal(legRctBytes, lReceiptConsensusEnc) { + t.Errorf("legacy receipt encoding (%x) does not match the expected consensus encoding (%x)", legRctBytes, lReceiptConsensusEnc) + } + + alRctWriter := new(bytes.Buffer) + if err := rct.Encode(accessListReceiptNode, alRctWriter); err != nil { + t.Fatalf("unable to encode access list receipt into writer: %v", err) + } + alRctBytes := alRctWriter.Bytes() + if !bytes.Equal(alRctBytes, alReceiptConsensusEnc) { + t.Errorf("access list receipt encoding (%x) does not match the expected consensus encoding (%x)", alRctBytes, alReceiptConsensusEnc) + } +} diff --git a/log/multicodec.go b/log/multicodec.go index 320172c..a8c14c4 100644 --- a/log/multicodec.go +++ b/log/multicodec.go @@ -16,7 +16,7 @@ var ( _ ipld.Decoder = Decode _ ipld.Encoder = Encode - MultiCodecType = uint64(0x9000) // TBD + MultiCodecType = uint64(0x9a) // Proposed MultiHashType = uint64(multihash.KECCAK_256) ) diff --git a/log/unmarshal.go b/log/unmarshal.go index aacfb77..bac840c 100644 --- a/log/unmarshal.go +++ b/log/unmarshal.go @@ -13,7 +13,7 @@ import ( // Decode provides an IPLD codec decode interface for eth log IPLDs. // This function is registered via the go-ipld-prime link loader for multicodec -// code TBD when this package is invoked via init. +// code 0x9a when this package is invoked via init. func Decode(na ipld.NodeAssembler, in io.Reader) error { var src []byte if buf, ok := in.(interface{ Bytes() []byte }); ok { diff --git a/log_trie/log_trie_test.go b/log_trie/log_trie_test.go new file mode 100644 index 0000000..3eeb59e --- /dev/null +++ b/log_trie/log_trie_test.go @@ -0,0 +1,622 @@ +package log_trie_test + +import ( + "bytes" + "encoding/binary" + "fmt" + "strconv" + "strings" + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/rlp" + "github.com/ipld/go-ipld-prime" + cidlink "github.com/ipld/go-ipld-prime/linking/cid" + "github.com/multiformats/go-multihash" + + dageth "github.com/vulcanize/go-codec-dageth" + "github.com/vulcanize/go-codec-dageth/rct_trie" + "github.com/vulcanize/go-codec-dageth/shared" + "github.com/vulcanize/go-codec-dageth/trie" +) + +var ( + mockHash = crypto.Keccak256([]byte{1, 2, 3, 4, 5}) + legacyReceipt = &types.Receipt{ + Status: types.ReceiptStatusSuccessful, + CumulativeGasUsed: 1, + Logs: []*types.Log{ + { + Address: common.BytesToAddress([]byte{0x11}), + Topics: []common.Hash{common.HexToHash("hello"), common.HexToHash("world")}, + Data: []byte{0x01, 0x00, 0xff}, + }, + { + Address: common.BytesToAddress([]byte{0x01, 0x11}), + Topics: []common.Hash{common.HexToHash("goodbye"), common.HexToHash("world")}, + Data: []byte{0x01, 0x00, 0xff}, + }, + }, + Type: types.LegacyTxType, + } + accessListReceipt = &types.Receipt{ + PostState: mockHash, + CumulativeGasUsed: 1, + Logs: []*types.Log{ + { + Address: common.BytesToAddress([]byte{0x11}), + Topics: []common.Hash{common.HexToHash("hello"), common.HexToHash("world")}, + Data: []byte{0x01, 0x00, 0xff}, + }, + { + Address: common.BytesToAddress([]byte{0x01, 0x11}), + Topics: []common.Hash{common.HexToHash("goodbye"), common.HexToHash("world")}, + Data: []byte{0x01, 0x00, 0xff}, + }, + }, + Type: types.AccessListTxType, + } + mockLegacyReceiptLeafVal, _ = legacyReceipt.MarshalBinary() + mockALReceiptLeafVal, _ = accessListReceipt.MarshalBinary() + mockLeafParitalPath = common.Hex2Bytes("3114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45") + mockDecodedLeafPartialPath = shared.CompactToHex(mockLeafParitalPath) + mockLeafNodeLegacyReceipt = []interface{}{ + mockLeafParitalPath, + mockLegacyReceiptLeafVal, + } + mockLeafNodeALReceipt = []interface{}{ + mockLeafParitalPath, + mockALReceiptLeafVal, + } + mockLeafNodeRLPLegacyReceipt, _ = rlp.EncodeToBytes(mockLeafNodeLegacyReceipt) + mockLeafNodeRLPALReceipt, _ = rlp.EncodeToBytes(mockLeafNodeALReceipt) + mockExtensionPartialPath = common.Hex2Bytes("1114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45") + mockDecodedExtensionPartialPath = shared.CompactToHex(mockExtensionPartialPath) + mockExtensionHash = crypto.Keccak256(mockLeafNodeRLPLegacyReceipt) + mockExtensionNode = []interface{}{ + mockExtensionPartialPath, + mockExtensionHash, + } + mockExtensionNodeRLP, _ = rlp.EncodeToBytes(mockExtensionNode) + mockChild0 = crypto.Keccak256([]byte{0}) + mockChild5 = crypto.Keccak256([]byte{5}) + mockChildE = crypto.Keccak256([]byte{14}) + mockBranchNode = []interface{}{ + mockChild0, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + mockChild5, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + mockChildE, + []byte{}, + mockLegacyReceiptLeafVal, + } + mockBranchNodeRLP, _ = rlp.EncodeToBytes(mockBranchNode) + + leafNodeLegacy, leafNodeAL, extensionNode, branchNode ipld.Node +) + +/* IPLD Schemas +type TrieNode union { + | TrieBranchNode "branch" + | TrieExtensionNode "extension" + | TrieLeafNode "leaf" +} representation keyed + +type TrieBranchNode struct { + Child0 nullable Child + Child1 nullable Child + Child2 nullable Child + Child3 nullable Child + Child4 nullable Child + Child5 nullable Child + Child6 nullable Child + Child7 nullable Child + Child8 nullable Child + Child9 nullable Child + ChildA nullable Child + ChildB nullable Child + ChildC nullable Child + ChildD nullable Child + ChildE nullable Child + ChildF nullable Child + Value nullable Value +} + +type Value union { + | Transaction "tx" + | Receipt "rct" + | Account "state" + | Bytes "storage" +} representation keyed + +type Child union { + | Link &TrieNode + | TrieNode TrieNode +} representation kinded + +type TrieExtensionNode struct { + PartialPath Bytes + Child Child +} + +type TrieLeafNode struct { + PartialPath Bytes + Value Value +} + +type Topics [Hash] + +type Log struct { + Address Address + Topics Topics + Data Bytes +} + +type Logs [Log] + +type Receipt struct { + TxType TxType + // We could make Status an enum + Status Uint // nullable + PostState Hash // nullable + CumulativeGasUsed Uint + Bloom Bloom + Logs Logs +} + +type Receipts [Receipt] +*/ + +func TestReceiptTrieCodec(t *testing.T) { + testReceiptTrieDecode(t) + testReceiptTrieNodeContents(t) + testReceiptTrieEncode(t) +} + +func testReceiptTrieDecode(t *testing.T) { + branchNodeBuilder := dageth.Type.TrieNode.NewBuilder() + branchNodeReader := bytes.NewReader(mockBranchNodeRLP) + if err := rct_trie.Decode(branchNodeBuilder, branchNodeReader); err != nil { + t.Fatalf("unable to decode receipt trie branch node into an IPLD node: %v", err) + } + branchNode = branchNodeBuilder.Build() + + extensionNodeBuilder := dageth.Type.TrieNode.NewBuilder() + extensionNodeReader := bytes.NewReader(mockExtensionNodeRLP) + if err := rct_trie.Decode(extensionNodeBuilder, extensionNodeReader); err != nil { + t.Fatalf("unable to decode receipt trie extension node into an IPLD node: %v", err) + } + extensionNode = extensionNodeBuilder.Build() + + leafNodeBuilderLegacy := dageth.Type.TrieNode.NewBuilder() + leafNodeReaderLegacy := bytes.NewReader(mockLeafNodeRLPLegacyReceipt) + if err := rct_trie.Decode(leafNodeBuilderLegacy, leafNodeReaderLegacy); err != nil { + t.Fatalf("unable to decode receipt trie leaf node into an IPLD node: %v", err) + } + leafNodeLegacy = leafNodeBuilderLegacy.Build() + + leafNodeBuilderAL := dageth.Type.TrieNode.NewBuilder() + leafNodeReaderAL := bytes.NewReader(mockLeafNodeRLPALReceipt) + if err := rct_trie.Decode(leafNodeBuilderAL, leafNodeReaderAL); err != nil { + t.Fatalf("unable to decode receipt trie leaf node into an IPLD node: %v", err) + } + leafNodeAL = leafNodeBuilderAL.Build() +} + +func testReceiptTrieNodeContents(t *testing.T) { + verifyBranchNodeContents(t) + verifyExtensionNodeContents(t) + verifyLegacyReceiptLeafNodeContents(t) + verifyALReceiptLeafNodeContents(t) +} + +func verifyBranchNodeContents(t *testing.T) { + branch, err := branchNode.LookupByString(trie.BRANCH_NODE.String()) + if err != nil { + t.Fatalf("receipt trie branch node missing enum key: %v", err) + } + nullChildren := []int{1, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 15} + for _, i := range nullChildren { + key := fmt.Sprintf("Child%s", strings.ToUpper(strconv.FormatInt(int64(i), 16))) + childNode, err := branch.LookupByString(key) + if err != nil { + t.Fatalf("receipt trie branch node missing %s: %v", key, err) + } + if !childNode.IsNull() { + t.Errorf("receipt trie branch node %s should be null", key) + } + } + child0Node, err := branch.LookupByString("Child0") + if err != nil { + t.Fatalf("receipt trie branch node missing Child0: %v", err) + } + // Why do we have to look up the Union as if it is keyed representation? + // It is kinded, we ought to be able to assert the node to a Link (call .AsLink on child0Node) + child0LinkNode, err := child0Node.LookupByString("Link") + if err != nil { + t.Fatalf("receipt trie branch node Child0 should be of type Link: %v", err) + } + child0Link, err := child0LinkNode.AsLink() + if err != nil { + t.Fatalf("receipt trie branch node Child0 should be of type Link: %v", err) + } + child0CIDLink, ok := child0Link.(cidlink.Link) + if !ok { + t.Fatalf("receipt trie branch node Child0 should be a CID: %v", err) + } + child0Mh := child0CIDLink.Hash() + decodedChild0Mh, err := multihash.Decode(child0Mh) + if err != nil { + t.Fatalf("could not decode branch node Child0 multihash: %v", err) + } + if !bytes.Equal(decodedChild0Mh.Digest, mockChild0) { + t.Errorf("receipt trie branch node child0 hash (%x) does not match expected hash (%d)", decodedChild0Mh.Digest, mockChild0) + } + + child5Node, err := branch.LookupByString("Child5") + if err != nil { + t.Fatalf("receipt trie branch node missing Child5: %v", err) + } + child5LinkNode, err := child5Node.LookupByString("Link") + if err != nil { + t.Fatalf("receipt trie branch node Child5 should be of type Link: %v", err) + } + child5Link, err := child5LinkNode.AsLink() + if err != nil { + t.Fatalf("receipt trie branch node Child5 should be of type Link: %v", err) + } + child5CIDLink, ok := child5Link.(cidlink.Link) + if !ok { + t.Fatalf("receipt trie branch node Child5 should be a CID: %v", err) + } + child5Mh := child5CIDLink.Hash() + decodedChild5Mh, err := multihash.Decode(child5Mh) + if err != nil { + t.Fatalf("could not decode branch node Child5 multihash: %v", err) + } + if !bytes.Equal(decodedChild5Mh.Digest, mockChild5) { + t.Errorf("receipt trie branch node child5 hash (%x) does not match expected hash (%d)", decodedChild5Mh.Digest, mockChild0) + } + + childENode, err := branch.LookupByString("ChildE") + if err != nil { + t.Fatalf("receipt trie branch node missing ChildE: %v", err) + } + childELinkNode, err := childENode.LookupByString("Link") + if err != nil { + t.Fatalf("receipt trie branch node ChildE should be of type Link: %v", err) + } + childELink, err := childELinkNode.AsLink() + if err != nil { + t.Fatalf("receipt trie branch node ChildE should be of type Link: %v", err) + } + childECIDLink, ok := childELink.(cidlink.Link) + if !ok { + t.Fatalf("receipt trie branch node ChildE should be a CID: %v", err) + } + childEMh := childECIDLink.Hash() + decodedChildEMh, err := multihash.Decode(childEMh) + if err != nil { + t.Fatalf("could not decode branch node ChildE multihash: %v", err) + } + if !bytes.Equal(decodedChildEMh.Digest, mockChildE) { + t.Errorf("receipt trie branch node childE hash (%x) does not match expected hash (%d)", decodedChildEMh.Digest, mockChild0) + } + + valEnumNode, err := branch.LookupByString("Value") + if err != nil { + t.Fatalf("receipt trie branch node missing Value: %v", err) + } + verifyLegacyReceiptLeafValue(valEnumNode, t) +} + +func verifyExtensionNodeContents(t *testing.T) { + ext, err := extensionNode.LookupByString(trie.EXTENSION_NODE.String()) + if err != nil { + t.Fatalf("receipt trie extension node missing enum key: %v", err) + } + + extPathNode, err := ext.LookupByString("PartialPath") + if err != nil { + t.Fatalf("receipt trie extension node missing PartialPath: %v", err) + } + extPathBytes, err := extPathNode.AsBytes() + if err != nil { + t.Fatalf("receipt trie extension node PartialPath should be of type Bytes: %v", err) + } + if !bytes.Equal(extPathBytes, mockDecodedExtensionPartialPath) { + t.Errorf("receipt trie extension node partial path (%x) does not match expected partial path (%x)", extPathBytes, mockExtensionPartialPath) + } + + childNode, err := ext.LookupByString("Child") + if err != nil { + t.Fatalf("receipt trie extension node missing Child: %v", err) + } + childLinkNode, err := childNode.LookupByString("Link") + if err != nil { + t.Fatalf("receipt trie extension node Child should be of kind Link: %v", err) + } + childLink, err := childLinkNode.AsLink() + if err != nil { + t.Fatalf("receipt trie extension node Child should be of kind Link: %v", err) + } + childCIDLink, ok := childLink.(cidlink.Link) + if !ok { + t.Fatalf("receipt trie extension node Child is not a CID: %v", err) + } + childMh := childCIDLink.Hash() + decodedChildMh, err := multihash.Decode(childMh) + if err != nil { + t.Fatalf("receipt trie extension node Child could not be decoded into multihash: %v", err) + } + if !bytes.Equal(decodedChildMh.Digest, mockExtensionHash) { + t.Errorf("receipt trie extension node child hash (%x) does not match expected hash (%x)", decodedChildMh.Digest, mockExtensionHash) + } +} + +func verifyALReceiptLeafNodeContents(t *testing.T) { + leaf, err := leafNodeAL.LookupByString(trie.LEAF_NODE.String()) + if err != nil { + t.Fatalf("unable to resolve TrieNode union to a leaf: %v", err) + } + + leafPathNode, err := leaf.LookupByString("PartialPath") + if err != nil { + t.Fatalf("receipt trie leaf node missing PartialPath: %v", err) + } + leafPathBytes, err := leafPathNode.AsBytes() + if err != nil { + t.Fatalf("receipt trie leaf node PartialPath should be of type Bytes: %v", err) + } + + if !bytes.Equal(leafPathBytes, mockDecodedLeafPartialPath) { + t.Errorf("receipt trie leaf node partial path (%x) does not match expected partial path (%x)", leafPathBytes, mockDecodedLeafPartialPath) + } + + valEnumNode, err := leaf.LookupByString("Value") + if err != nil { + t.Fatalf("receipt trie leaf node missing Value: %v", err) + } + verifyALReceiptLeafValue(valEnumNode, t) +} + +func verifyLegacyReceiptLeafNodeContents(t *testing.T) { + leaf, err := leafNodeLegacy.LookupByString(trie.LEAF_NODE.String()) + if err != nil { + t.Fatalf("unable to resolve TrieNode union to a leaf: %v", err) + } + + leafPathNode, err := leaf.LookupByString("PartialPath") + if err != nil { + t.Fatalf("receipt trie leaf node missing PartialPath: %v", err) + } + leafPathBytes, err := leafPathNode.AsBytes() + if err != nil { + t.Fatalf("receipt trie leaf node PartialPath should be of type Bytes: %v", err) + } + + if !bytes.Equal(leafPathBytes, mockDecodedLeafPartialPath) { + t.Errorf("receipt trie leaf node partial path (%x) does not match expected partial path (%x)", leafPathBytes, mockDecodedLeafPartialPath) + } + + valEnumNode, err := leaf.LookupByString("Value") + if err != nil { + t.Fatalf("receipt trie leaf node missing Value: %v", err) + } + verifyLegacyReceiptLeafValue(valEnumNode, t) +} + +func verifyALReceiptLeafValue(valEnumNode ipld.Node, t *testing.T) { + rctNode, err := valEnumNode.LookupByString(trie.RCT_VALUE.String()) + if err != nil { + t.Fatalf("unable to resolve Value union to a receipt: %v", err) + } + + verifySharedContent(t, rctNode, accessListReceipt) + statusNode, err := rctNode.LookupByString("Status") + if err != nil { + t.Fatalf("receipt is missing Status: %v", err) + } + if !statusNode.IsNull() { + t.Fatalf("receipt Status should be null") + } + + postStateNode, err := rctNode.LookupByString("PostState") + if err != nil { + t.Fatalf("receipt is missing PostState: %v", err) + } + if postStateNode.IsNull() { + t.Errorf("receipt PostState should not be null") + } + postStateBy, err := postStateNode.AsBytes() + if err != nil { + t.Fatalf("receipt PostState should be of type Bytes: %v", err) + } + if !bytes.Equal(postStateBy, accessListReceipt.PostState) { + t.Errorf("receipt post state (%d) does not match expected post state (%d)", postStateBy, accessListReceipt.PostState) + } +} + +func verifyLegacyReceiptLeafValue(valEnumNode ipld.Node, t *testing.T) { + rctNode, err := valEnumNode.LookupByString(trie.RCT_VALUE.String()) + if err != nil { + t.Fatalf("unable to resolve Value union to a receipt: %v", err) + } + + verifySharedContent(t, rctNode, legacyReceipt) + statusNode, err := rctNode.LookupByString("Status") + if err != nil { + t.Fatalf("receipt is missing Status: %v", err) + } + if statusNode.IsNull() { + t.Fatalf("receipt Status should not be null") + } + statusBy, err := statusNode.AsBytes() + if err != nil { + t.Fatalf("receipt Status should be of type Bytes: %v", err) + } + status := binary.BigEndian.Uint64(statusBy) + if status != legacyReceipt.Status { + t.Errorf("receipt status (%d) does not match expected status (%d)", status, legacyReceipt.Status) + } + + postStateNode, err := rctNode.LookupByString("PostState") + if err != nil { + t.Fatalf("receipt is missing PostState: %v", err) + } + if !postStateNode.IsNull() { + t.Errorf("receipt PostState should be null") + } +} + +func verifySharedContent(t *testing.T, rctNode ipld.Node, rct *types.Receipt) { + typeNode, err := rctNode.LookupByString("TxType") + if err != nil { + t.Fatalf("receipt is missing TxType: %v", err) + } + typeBy, err := typeNode.AsBytes() + if err != nil { + t.Fatalf("receipt TxType should be of type Bytes: %v", err) + } + if len(typeBy) != 1 { + t.Fatalf("receipt TxType should be a single byte") + } + if typeBy[0] != rct.Type { + t.Errorf("receipt tx type (%d) does not match expected tx type (%d)", typeBy[0], rct.Type) + } + + cguNode, err := rctNode.LookupByString("CumulativeGasUsed") + if err != nil { + t.Fatalf("receipt is missing CumulativeGasUsed: %v", err) + } + cguBy, err := cguNode.AsBytes() + if err != nil { + t.Fatalf("receipt CumulativeGasUsed should be of type Bytes: %v", err) + } + cgu := binary.BigEndian.Uint64(cguBy) + if cgu != rct.CumulativeGasUsed { + t.Errorf("receipt cumulative gas used (%d) does not match expected cumulative gas used (%d)", cgu, rct.CumulativeGasUsed) + } + + bloomNode, err := rctNode.LookupByString("Bloom") + if err != nil { + t.Fatalf("receipt is missing Bloom: %v", err) + } + bloomBy, err := bloomNode.AsBytes() + if err != nil { + t.Fatalf("receipt Bloom should be of type Bytes: %v", err) + } + if !bytes.Equal(bloomBy, rct.Bloom.Bytes()) { + t.Errorf("receipt bloom (%x) does not match expected bloom (%x)", bloomBy, rct.Bloom.Bytes()) + } + + logsNode, err := rctNode.LookupByString("Logs") + if err != nil { + t.Fatalf("receipt is missing Logs: %v", err) + } + if logsNode.Length() != int64(len(rct.Logs)) { + t.Fatalf("receipt should have %d logs", len(rct.Logs)) + } + logsLI := logsNode.ListIterator() + for !logsLI.Done() { + i, logNode, err := logsLI.Next() + if err != nil { + t.Fatalf("receipt log iterator error: %v", err) + } + currentLog := rct.Logs[i] + addrNode, err := logNode.LookupByString("Address") + if err != nil { + t.Fatalf("receipt log is missing Address: %v", err) + } + addrBy, err := addrNode.AsBytes() + if err != nil { + t.Fatalf("receipt log Address should be of type Bytes: %v", err) + } + if !bytes.Equal(addrBy, currentLog.Address.Bytes()) { + t.Errorf("receipt log address (%x) does not match expected address (%x)", addrBy, currentLog.Address.Bytes()) + } + dataNode, err := logNode.LookupByString("Data") + if err != nil { + t.Fatalf("receipt log is missing Data: %v", err) + } + data, err := dataNode.AsBytes() + if err != nil { + t.Fatalf("receipt log Data should be of type Bytes: %v", err) + } + if !bytes.Equal(data, currentLog.Data) { + t.Errorf("receipt log data (%x) does not match expected data (%x)", data, currentLog.Data) + } + topicsNode, err := logNode.LookupByString("Topics") + if err != nil { + t.Fatalf("receipt log is missing Topics: %v", err) + } + if topicsNode.Length() != 2 { + t.Fatal("receipt log should have two topics") + } + topicsLI := topicsNode.ListIterator() + for !topicsLI.Done() { + j, topicNode, err := topicsLI.Next() + if err != nil { + t.Fatalf("receipt log topic iterator error: %v", err) + } + currentTopic := currentLog.Topics[j].Bytes() + topicBy, err := topicNode.AsBytes() + if err != nil { + t.Fatalf("receipt log Topic should be of type Bytes: %v", err) + } + if !bytes.Equal(topicBy, currentTopic) { + t.Errorf("receipt log topic%d bytes (%x) does not match expected bytes (%x)", j, topicBy, currentTopic) + } + } + } +} + +func testReceiptTrieEncode(t *testing.T) { + branchWriter := new(bytes.Buffer) + if err := rct_trie.Encode(branchNode, branchWriter); err != nil { + t.Fatalf("unable to encode receipt trie branch node into writer: %v", err) + } + encodedBranchBytes := branchWriter.Bytes() + if !bytes.Equal(encodedBranchBytes, mockBranchNodeRLP) { + t.Errorf("receipt trie branch node encoding (%x) does not match the expected consensus encoding (%x)", encodedBranchBytes, mockBranchNodeRLP) + } + + extensionWriter := new(bytes.Buffer) + if err := rct_trie.Encode(extensionNode, extensionWriter); err != nil { + t.Fatalf("unable to encode receipt trie extension node into writer: %v", err) + } + encodedExtensionBytes := extensionWriter.Bytes() + if !bytes.Equal(encodedExtensionBytes, mockExtensionNodeRLP) { + t.Errorf("receipt trie extension node encoding (%x) does not match the expected consensus encoding (%x)", encodedExtensionBytes, mockExtensionNodeRLP) + } + + leafWriterLegacyReceipt := new(bytes.Buffer) + if err := rct_trie.Encode(leafNodeLegacy, leafWriterLegacyReceipt); err != nil { + t.Fatalf("unable to encode receipt trie leaf node into writer: %v", err) + } + encodedLeafBytesLegacyReceipt := leafWriterLegacyReceipt.Bytes() + if !bytes.Equal(encodedLeafBytesLegacyReceipt, mockLeafNodeRLPLegacyReceipt) { + t.Errorf("receipt trie leaf node encoding (%x) does not match the expected consenus encoding (%x)", encodedLeafBytesLegacyReceipt, mockLeafNodeRLPLegacyReceipt) + } + + leafWriterALReceipt := new(bytes.Buffer) + if err := rct_trie.Encode(leafNodeAL, leafWriterALReceipt); err != nil { + t.Fatalf("unable to encode receipt trie leaf node into writer: %v", err) + } + encodedLeafBytesALReceipt := leafWriterALReceipt.Bytes() + if !bytes.Equal(encodedLeafBytesALReceipt, mockLeafNodeRLPALReceipt) { + t.Errorf("receipt trie leaf node encoding (%x) does not match the expected consenus encoding (%x)", encodedLeafBytesALReceipt, mockLeafNodeRLPALReceipt) + } +} diff --git a/log_trie/multicodec.go b/log_trie/multicodec.go index f77b2b2..3219746 100644 --- a/log_trie/multicodec.go +++ b/log_trie/multicodec.go @@ -3,7 +3,6 @@ package log_trie import ( "io" - "github.com/ipfs/go-cid" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" "github.com/ipld/go-ipld-prime/multicodec" @@ -17,7 +16,7 @@ var ( _ ipld.Decoder = Decode _ ipld.Encoder = Encode - MultiCodecType = uint64(cid.EthTxReceiptTrie) // TBD + MultiCodecType = uint64(0x99) // Proposed MultiHashType = uint64(multihash.KECCAK_256) ) diff --git a/log_trie/unmarshal.go b/log_trie/unmarshal.go index f672e1d..9691c63 100644 --- a/log_trie/unmarshal.go +++ b/log_trie/unmarshal.go @@ -10,7 +10,7 @@ import ( // Decode provides an IPLD codec decode interface for eth log trie node IPLDs. // This function is registered via the go-ipld-prime link loader for multicodec -// code 0x94 when this package is invoked via init. +// code 0x99 (proposed) when this package is invoked via init. // This simply wraps dageth_trie.DecodeTrieNode with the proper multicodec type func Decode(na ipld.NodeAssembler, in io.Reader) error { return dageth_trie.DecodeTrieNode(na, in, MultiCodecType) From 9dd2daf64f36ce29c2d506924a80dd84c61c122a Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 10 Aug 2021 11:39:09 -0500 Subject: [PATCH 07/11] log marshaller and unmarshaller unit tests --- go.mod | 3 +- go.sum | 54 -------- log/log_test.go | 325 ++++++++---------------------------------------- rct/rct_test.go | 13 +- tx/tx_test.go | 9 ++ 5 files changed, 75 insertions(+), 329 deletions(-) diff --git a/go.mod b/go.mod index 500ea92..8707352 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,9 @@ go 1.15 require ( github.com/ethereum/go-ethereum v1.10.4 github.com/ipfs/go-cid v0.0.7 - github.com/ipfs/go-ipfs-blockstore v1.0.4 - github.com/ipfs/go-ipfs-ds-help v1.0.0 github.com/ipld/go-ipld-prime v0.10.0 github.com/multiformats/go-multihash v0.0.15 + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect ) replace github.com/ethereum/go-ethereum v1.10.4 => github.com/vulcanize/go-ethereum v1.10.4-ir-0.0.1 diff --git a/go.sum b/go.sum index 5a2304d..2be95e1 100644 --- a/go.sum +++ b/go.sum @@ -89,7 +89,6 @@ github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea h1:j4317fAZh7X6GqbFowYdYdI0L9bwxL07jyPZIdepyZ0= github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-bitstream v0.0.0-20180413035011-3522498ce2c8/go.mod h1:VMaSuZ+SZcx/wljOQKvp5srsbCiKDEb6K2wC4+PiBmQ= @@ -98,7 +97,6 @@ github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55k github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/dop251/goja v0.0.0-20200721192441-a695b0cdd498/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA= github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts= -github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw= github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= @@ -127,8 +125,6 @@ github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= -github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= @@ -169,24 +165,19 @@ github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OI github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.1.5 h1:kxhtnfFVi+rYdOALN0B3k9UT86zVJKfBimRaciULW4I= github.com/google/uuid v1.1.5/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/graph-gophers/graphql-go v0.0.0-20201113091052-beb923fada29/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d h1:dg1dEPuWpEqDnvIw251EVy4zlP8gWbsGj4BsUKCRpYs= github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= -github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM= github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huin/goupnp v1.0.1-0.20210310174557-0ca763054c88/go.mod h1:nNs7wvRfN1eKaMknBydLNQU6146XQim8t4h+q90biWo= @@ -201,36 +192,12 @@ github.com/influxdata/promql/v2 v2.12.0/go.mod h1:fxOPu+DY0bqCTCECchSRtWfc+0X19y github.com/influxdata/roaring v0.4.13-0.20180809181101-fc520f41fab6/go.mod h1:bSgUQ7q5ZLSO+bKBGqJiCBGAl+9DxyW63zLTujjUlOE= github.com/influxdata/tdigest v0.0.0-20181121200506-bf2b5ad3c0a9/go.mod h1:Js0mqiSBE6Ffsg94weZZ2c+v/ciT8QRHFOap7EKDrR0= github.com/influxdata/usage-client v0.0.0-20160829180054-6d3895376368/go.mod h1:Wbbw6tYNvwa5dlB6304Sd+82Z3f7PmVZHVKU637d4po= -github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs= -github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0= -github.com/ipfs/go-block-format v0.0.3 h1:r8t66QstRp/pd/or4dpnbVfXT5Gt7lOqRvC+/dDTpMc= -github.com/ipfs/go-block-format v0.0.3/go.mod h1:4LmD4ZUw0mhO+JSKdpWwrzATiEfM7WWgQ8H5l6P8MVk= -github.com/ipfs/go-cid v0.0.4 h1:UlfXKrZx1DjZoBhQHmNHLC1fK1dUJDN20Y28A7s+gJ8= github.com/ipfs/go-cid v0.0.4/go.mod h1:4LLaPOQwmk5z9LBgQnpkivrx8BJjUyGwTXCd5Xfj6+M= -github.com/ipfs/go-cid v0.0.5/go.mod h1:plgt+Y5MnOey4vO4UlUazGqdbEXuFYitED67FexhXog= github.com/ipfs/go-cid v0.0.7 h1:ysQJVJA3fNDF1qigJbsSQOdjhVLsOEoPdh0+R97k3jY= github.com/ipfs/go-cid v0.0.7/go.mod h1:6Ux9z5e+HpkQdckYoX1PG/6xqKspzlEIR5SDmgqgC/I= -github.com/ipfs/go-datastore v0.4.1/go.mod h1:SX/xMIKoCszPqp+z9JhPYCmoOoXTvaa13XEbGtsFUhA= -github.com/ipfs/go-datastore v0.4.2 h1:h8/n7WPzhp239kkLws+epN3Ic7YtcBPgcaXfEfdVDWM= -github.com/ipfs/go-datastore v0.4.2/go.mod h1:SX/xMIKoCszPqp+z9JhPYCmoOoXTvaa13XEbGtsFUhA= -github.com/ipfs/go-ipfs-blockstore v1.0.4 h1:DZdeya9Vu4ttvlGheQPGrj6kWehXnYZRFCp9EsZQ1hI= -github.com/ipfs/go-ipfs-blockstore v1.0.4/go.mod h1:uL7/gTJ8QIZ3MtA3dWf+s1a0U3fJy2fcEZAsovpRp+w= -github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw= -github.com/ipfs/go-ipfs-ds-help v1.0.0 h1:bEQ8hMGs80h0sR8O4tfDgV6B01aaF9qeTrujrTLYV3g= -github.com/ipfs/go-ipfs-ds-help v1.0.0/go.mod h1:ujAbkeIgkKAWtxxNkoZHWLCyk5JpPoKnGyCcsoF6ueE= -github.com/ipfs/go-ipfs-util v0.0.2 h1:59Sswnk1MFaiq+VcaknX7aYEyGyGDAA73ilhEK2POp8= -github.com/ipfs/go-ipfs-util v0.0.2/go.mod h1:CbPtkWJzjLdEcezDns2XYaehFVNXG9zrdrtMecczcsQ= -github.com/ipfs/go-log v0.0.1 h1:9XTUN/rW64BCG1YhPK9Hoy3q8nr4gOmHHBpgFdfw6Lc= -github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= -github.com/ipfs/go-metrics-interface v0.0.1 h1:j+cpbjYvu4R8zbleSs36gvB7jR+wsL2fGD6n0jO4kdg= -github.com/ipfs/go-metrics-interface v0.0.1/go.mod h1:6s6euYU4zowdslK0GKHmqaIZ3j/b/tL7HTWtJ4VPgWY= -github.com/ipld/go-ipld-prime v0.9.0 h1:N2OjJMb+fhyFPwPnVvJcWU/NsumP8etal+d2v3G4eww= -github.com/ipld/go-ipld-prime v0.9.0/go.mod h1:KvBLMr4PX1gWptgkzRjVZCrLmSGcZCb/jioOQwCqZN8= github.com/ipld/go-ipld-prime v0.10.0 h1:ZCd52SDUqvA3YUJEx9v2uIm1qWv6FAxBt2mhiFpoZ6s= github.com/ipld/go-ipld-prime v0.10.0/go.mod h1:KvBLMr4PX1gWptgkzRjVZCrLmSGcZCb/jioOQwCqZN8= github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= -github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8 h1:bspPhN+oKYFk5fcGNuQzp6IGzYQSenLEgH3s6jkXrWw= -github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8/go.mod h1:Ly/wlsjFq/qrU3Rar62tu1gASgGw6chQbSh/XgIIXCY= github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e/go.mod h1:G1CVv03EnqU1wYL2dFwXxW2An0az9JTl/ZsqXQeBlkU= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= @@ -246,7 +213,6 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= github.com/jwilder/encoding v0.0.0-20170811194829-b4e1701a28ef/go.mod h1:Ct9fl0F6iIOGgxJ5npU/IUOhOhqlVrGjyIZc8/MagT0= github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU= -github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= @@ -271,14 +237,10 @@ github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2 github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg= -github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.5 h1:tHXDdz1cpzGaovsTB+TVB8q90WEokoVmfMqoVcrLUgw= -github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= @@ -302,13 +264,11 @@ github.com/multiformats/go-base32 v0.0.3 h1:tw5+NhuwaOjJCC5Pp82QuXbrmLzWg7uxlMFp github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= github.com/multiformats/go-base36 v0.1.0 h1:JR6TyF7JjGd3m6FbLU2cOxhC0Li8z8dLNGQ89tUg4F4= github.com/multiformats/go-base36 v0.1.0/go.mod h1:kFGE83c6s80PklsHO9sRn2NCoffoRdUUOENyW/Vv6sM= -github.com/multiformats/go-multibase v0.0.1 h1:PN9/v21eLywrFWdFNsFKaU04kLJzuYzmrJR+ubhT9qA= github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multibase v0.0.3 h1:l/B6bJDQjvQ5G52jw4QGSYeOTZoAwIO77RblWplfIqk= github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc= github.com/multiformats/go-multihash v0.0.10/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc= -github.com/multiformats/go-multihash v0.0.14/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc= github.com/multiformats/go-multihash v0.0.15 h1:hWOPdrNqDjwHDx82vsYGSDZNyktOJJ2dzZJzFkOV1jM= github.com/multiformats/go-multihash v0.0.15/go.mod h1:D6aZrWNLFTV/ynMpKsNtB40mJzmCl4jb1alC0OvHiHg= github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= @@ -333,7 +293,6 @@ github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.0.3-0.20180606204148-bd9c31933947/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= -github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/paulbellamy/ratecounter v0.2.0/go.mod h1:Hfx1hDpSGoqxkVVpBi/IlYD7kChlfo5C6hzIHwPqfFE= github.com/peterh/liner v1.0.1-0.20180619022028-8c1271fcf47f/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc= @@ -404,8 +363,6 @@ github.com/vulcanize/go-ethereum v1.10.4-ir-0.0.1 h1:ctKWxcy/VvRBWJNFGlkij/4SV60 github.com/vulcanize/go-ethereum v1.10.4-ir-0.0.1/go.mod h1:nEE0TP5MtxGzOMd7egIrbPJMQBnhVU3ELNxhBglIzhg= github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a h1:G++j5e0OC488te356JvdhaM8YS6nMsjLAYF7JxCv07w= github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw= -github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc h1:9lDbC6Rz4bwmou+oE6Dt4Cb2BGMur5eR/GYptkKUVHo= -github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -413,8 +370,6 @@ go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk= -go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -449,7 +404,6 @@ golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= @@ -457,7 +411,6 @@ golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKG golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -466,7 +419,6 @@ golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190227160552-c95aed5357e7/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -502,7 +454,6 @@ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -539,7 +490,6 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -559,7 +509,6 @@ golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -567,7 +516,6 @@ golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200108203644-89082a384178/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -620,13 +568,11 @@ google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyz google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c= gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6/go.mod h1:uAJfkITjFhyEEuUfm7bsmCZRbW5WRq8s9EY8HZ6hCns= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= diff --git a/log/log_test.go b/log/log_test.go index f426a1e..c0db63c 100644 --- a/log/log_test.go +++ b/log/log_test.go @@ -2,12 +2,11 @@ package log_test import ( "bytes" - "encoding/binary" "testing" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/rlp" "github.com/ipld/go-ipld-prime" dageth "github.com/vulcanize/go-codec-dageth" @@ -15,61 +14,15 @@ import ( ) var ( - mockHash = crypto.Keccak256([]byte{1, 2, 3, 4, 5}) - legacyReceipt = &types.Receipt{ - Status: types.ReceiptStatusSuccessful, - CumulativeGasUsed: 1, - Logs: []*types.Log{ - { - Address: common.BytesToAddress([]byte{0x11}), - Topics: []common.Hash{common.HexToHash("hello"), common.HexToHash("world")}, - Data: []byte{0x01, 0x00, 0xff}, - }, - { - Address: common.BytesToAddress([]byte{0x01, 0x11}), - Topics: []common.Hash{common.HexToHash("goodbye"), common.HexToHash("world")}, - Data: []byte{0x01, 0x00, 0xff}, - }, - }, - Type: types.LegacyTxType, - } - accessListReceipt = &types.Receipt{ - PostState: mockHash, - CumulativeGasUsed: 1, - Logs: []*types.Log{ - { - Address: common.BytesToAddress([]byte{0x11}), - Topics: []common.Hash{common.HexToHash("hello"), common.HexToHash("world")}, - Data: []byte{0x01, 0x00, 0xff}, - }, - { - Address: common.BytesToAddress([]byte{0x01, 0x11}), - Topics: []common.Hash{common.HexToHash("goodbye"), common.HexToHash("world")}, - Data: []byte{0x01, 0x00, 0xff}, - }, - }, - Type: types.AccessListTxType, - } - dynamicFeeReceipt = &types.Receipt{ - Status: types.ReceiptStatusSuccessful, - CumulativeGasUsed: 1, - Logs: []*types.Log{ - { - Address: common.BytesToAddress([]byte{0x11}), - Topics: []common.Hash{common.HexToHash("hello"), common.HexToHash("world")}, - Data: []byte{0x01, 0x00, 0xff}, - }, - { - Address: common.BytesToAddress([]byte{0x01, 0x11}), - Topics: []common.Hash{common.HexToHash("goodbye"), common.HexToHash("world")}, - Data: []byte{0x01, 0x00, 0xff}, - }, - }, - Type: types.DynamicFeeTxType, - } - - lReceiptConsensusEnc, alReceiptConsensusEnc, dfReceiptConsensusEnc []byte - legacyReceiptNode, accessListReceiptNode, dynamicFeeReceiptNode ipld.Node + mockLog = &types.Log{ + Address: common.BytesToAddress([]byte{0x11}), + Topics: []common.Hash{common.HexToHash("hello"), common.HexToHash("moon"), common.HexToHash("goodbye"), common.HexToHash("world")}, + Data: []byte{0x01, 0x00, 0xff, 0x01, 0x00, 0xff, 0x01, 0x00, 0xff, 0x01, 0x00, 0xff, 0x01, 0x00, 0xff, 0x01, + 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, + 0x03, 0x02, 0x01, 0x03, 0x02, 0x01, 0x03, 0x02, 0x01, 0x03, 0x02, 0x01, 0x03, 0x02, 0x01, 0x03}, + } + logEncoding, _ = rlp.EncodeToBytes(mockLog) + logNode ipld.Node ) /* IPLD Schemas @@ -80,251 +33,79 @@ type Log struct { Topics Topics Data Bytes } - -type Logs [Log] - -type Receipt struct { - TxType TxType - Status nullable Uint - PostState nullable Hash - CumulativeGasUsed Uint - Bloom Bloom - Logs Logs -} - -type Receipts [Receipt] */ -func TestReceiptCodec(t *testing.T) { - var err error - lReceiptConsensusEnc, err = legacyReceipt.MarshalBinary() - if err != nil { - t.Fatalf("unable to marshal legacy receipt binary: %v", err) - } - alReceiptConsensusEnc, err = accessListReceipt.MarshalBinary() - if err != nil { - t.Fatalf("unable to marshal access list receipt binary: %v", err) - } - testReceiptDecoding(t) - testAccessListReceiptNodeContents(t) - testLegacyReceiptNodeContents(t) - testReceiptEncoding(t) -} - -func testReceiptDecoding(t *testing.T) { - legacyRctBuilder := dageth.Type.Receipt.NewBuilder() - legacyRctReader := bytes.NewReader(lReceiptConsensusEnc) - if err := rct.Decode(legacyRctBuilder, legacyRctReader); err != nil { - t.Fatalf("unable to decode legacy receipt into an IPLD node: %v", err) - } - legacyReceiptNode = legacyRctBuilder.Build() - - alRctBuilder := dageth.Type.Receipt.NewBuilder() - alRctReader := bytes.NewReader(alReceiptConsensusEnc) - if err := rct.Decode(alRctBuilder, alRctReader); err != nil { - t.Fatalf("unable to decode access list receipt into an IPLD node: %v", err) - } - accessListReceiptNode = alRctBuilder.Build() +func TestLogCodec(t *testing.T) { + testLogDecoding(t) + testLogNodeContents(t) + testLogEncoding(t) } -func testAccessListReceiptNodeContents(t *testing.T) { - verifySharedContent(t, accessListReceiptNode, accessListReceipt) - statusNode, err := accessListReceiptNode.LookupByString("Status") - if err != nil { - t.Fatalf("receipt is missing Status: %v", err) - } - if !statusNode.IsNull() { - t.Fatalf("receipt Status should be null") - } - - postStateNode, err := accessListReceiptNode.LookupByString("PostState") - if err != nil { - t.Fatalf("receipt is missing PostState: %v", err) - } - if postStateNode.IsNull() { - t.Errorf("receipt PostState should not be null") - } - postStateBy, err := postStateNode.AsBytes() - if err != nil { - t.Fatalf("receipt PostState should be of type Bytes: %v", err) - } - if !bytes.Equal(postStateBy, accessListReceipt.PostState) { - t.Errorf("receipt post state (%d) does not match expected post state (%d)", postStateBy, accessListReceipt.PostState) +func testLogDecoding(t *testing.T) { + logBuilder := dageth.Type.Log.NewBuilder() + logReader := bytes.NewReader(logEncoding) + if err := rct.Decode(logBuilder, logReader); err != nil { + t.Fatalf("unable to decode legacy Log into an IPLD node: %v", err) } + logNode = logBuilder.Build() } -func testDynamicFeeReceiptNodeContents(t *testing.T) { - verifySharedContent(t, dynamicFeeReceiptNode, dynamicFeeReceipt) - statusNode, err := dynamicFeeReceiptNode.LookupByString("Status") - if err != nil { - t.Fatalf("receipt is missing Status: %v", err) - } - if statusNode.IsNull() { - t.Fatalf("receipt Status should not be null") - } - statusBy, err := statusNode.AsBytes() +func testLogNodeContents(t *testing.T) { + addressNode, err := logNode.LookupByString("Address") if err != nil { - t.Fatalf("receipt Status should be of type Bytes: %v", err) - } - status := binary.BigEndian.Uint64(statusBy) - if status != dynamicFeeReceipt.Status { - t.Errorf("receipt status (%d) does not match expected status (%d)", status, dynamicFeeReceipt.Status) + t.Fatalf("log is missing Address: %v", err) } - - postStateNode, err := dynamicFeeReceiptNode.LookupByString("PostState") + addrBytes, err := addressNode.AsBytes() if err != nil { - t.Fatalf("receipt is missing PostState: %v", err) + t.Fatalf("log Address should be of type Bytes") } - if !postStateNode.IsNull() { - t.Errorf("receipt PostState should be null") + if !bytes.Equal(addrBytes, mockLog.Address.Bytes()) { + t.Errorf("log Address (%x) does not match expected Address (%x)", addrBytes, mockLog.Address.Bytes()) } -} -func testLegacyReceiptNodeContents(t *testing.T) { - verifySharedContent(t, legacyReceiptNode, legacyReceipt) - statusNode, err := legacyReceiptNode.LookupByString("Status") + dataNode, err := logNode.LookupByString("data") if err != nil { - t.Fatalf("receipt is missing Status: %v", err) + t.Fatalf("log is missing Data: %v", err) } - if statusNode.IsNull() { - t.Fatalf("receipt Status should not be null") - } - statusBy, err := statusNode.AsBytes() + data, err := dataNode.AsBytes() if err != nil { - t.Fatalf("receipt Status should be of type Bytes: %v", err) + t.Fatalf("log Data should be of type Bytes") } - status := binary.BigEndian.Uint64(statusBy) - if status != legacyReceipt.Status { - t.Errorf("receipt status (%d) does not match expected status (%d)", status, legacyReceipt.Status) + if !bytes.Equal(data, mockLog.Data) { + t.Errorf("log Data (%x) does not match expected data (%x)", data, mockLog.Data) } - postStateNode, err := legacyReceiptNode.LookupByString("PostState") + topicsNode, err := logNode.LookupByString("Topics") if err != nil { - t.Fatalf("receipt is missing PostState: %v", err) + t.Fatalf("log is missing Topics: %v", err) } - if !postStateNode.IsNull() { - t.Errorf("receipt PostState should be null") + if topicsNode.Length() != 4 { + t.Fatal("log should have two topics") } -} - -func verifySharedContent(t *testing.T, rctNode ipld.Node, rct *types.Receipt) { - typeNode, err := rctNode.LookupByString("TxType") - if err != nil { - t.Fatalf("receipt is missing TxType: %v", err) - } - typeBy, err := typeNode.AsBytes() - if err != nil { - t.Fatalf("receipt TxType should be of type Bytes: %v", err) - } - if len(typeBy) != 1 { - t.Fatalf("receipt TxType should be a single byte") - } - if typeBy[0] != rct.Type { - t.Errorf("receipt tx type (%d) does not match expected tx type (%d)", typeBy[0], rct.Type) - } - - cguNode, err := rctNode.LookupByString("CumulativeGasUsed") - if err != nil { - t.Fatalf("receipt is missing CumulativeGasUsed: %v", err) - } - cguBy, err := cguNode.AsBytes() - if err != nil { - t.Fatalf("receipt CumulativeGasUsed should be of type Bytes: %v", err) - } - cgu := binary.BigEndian.Uint64(cguBy) - if cgu != rct.CumulativeGasUsed { - t.Errorf("receipt cumulative gas used (%d) does not match expected cumulative gas used (%d)", cgu, rct.CumulativeGasUsed) - } - - bloomNode, err := rctNode.LookupByString("Bloom") - if err != nil { - t.Fatalf("receipt is missing Bloom: %v", err) - } - bloomBy, err := bloomNode.AsBytes() - if err != nil { - t.Fatalf("receipt Bloom should be of type Bytes: %v", err) - } - if !bytes.Equal(bloomBy, rct.Bloom.Bytes()) { - t.Errorf("receipt bloom (%x) does not match expected bloom (%x)", bloomBy, rct.Bloom.Bytes()) - } - - logsNode, err := rctNode.LookupByString("Logs") - if err != nil { - t.Fatalf("receipt is missing Logs: %v", err) - } - if logsNode.Length() != int64(len(rct.Logs)) { - t.Fatalf("receipt should have %d logs", len(rct.Logs)) - } - logsLI := logsNode.ListIterator() - for !logsLI.Done() { - i, logNode, err := logsLI.Next() - if err != nil { - t.Fatalf("receipt log iterator error: %v", err) - } - currentLog := rct.Logs[i] - addrNode, err := logNode.LookupByString("Address") + topicsLI := topicsNode.ListIterator() + for !topicsLI.Done() { + j, topicNode, err := topicsLI.Next() if err != nil { - t.Fatalf("receipt log is missing Address: %v", err) + t.Fatalf("receipt log topic iterator error: %v", err) } - addrBy, err := addrNode.AsBytes() + currentTopic := mockLog.Topics[j].Bytes() + topicBy, err := topicNode.AsBytes() if err != nil { - t.Fatalf("receipt log Address should be of type Bytes: %v", err) + t.Fatalf("log Topic should be of type Bytes: %v", err) } - if !bytes.Equal(addrBy, currentLog.Address.Bytes()) { - t.Errorf("receipt log address (%x) does not match expected address (%x)", addrBy, currentLog.Address.Bytes()) - } - dataNode, err := logNode.LookupByString("Data") - if err != nil { - t.Fatalf("receipt log is missing Data: %v", err) - } - data, err := dataNode.AsBytes() - if err != nil { - t.Fatalf("receipt log Data should be of type Bytes: %v", err) - } - if !bytes.Equal(data, currentLog.Data) { - t.Errorf("receipt log data (%x) does not match expected data (%x)", data, currentLog.Data) - } - topicsNode, err := logNode.LookupByString("Topics") - if err != nil { - t.Fatalf("receipt log is missing Topics: %v", err) - } - if topicsNode.Length() != 2 { - t.Fatal("receipt log should have two topics") - } - topicsLI := topicsNode.ListIterator() - for !topicsLI.Done() { - j, topicNode, err := topicsLI.Next() - if err != nil { - t.Fatalf("receipt log topic iterator error: %v", err) - } - currentTopic := currentLog.Topics[j].Bytes() - topicBy, err := topicNode.AsBytes() - if err != nil { - t.Fatalf("receipt log Topic should be of type Bytes: %v", err) - } - if !bytes.Equal(topicBy, currentTopic) { - t.Errorf("receipt log topic%d bytes (%x) does not match expected bytes (%x)", j, topicBy, currentTopic) - } + if !bytes.Equal(topicBy, currentTopic) { + t.Errorf("log topic%d (%x) does not match expected topic%d (%x)", j, topicBy, j, currentTopic) } } } -func testReceiptEncoding(t *testing.T) { - legRctWriter := new(bytes.Buffer) - if err := rct.Encode(legacyReceiptNode, legRctWriter); err != nil { - t.Fatalf("unable to encode legacy receipt into writer: %v", err) - } - legRctBytes := legRctWriter.Bytes() - if !bytes.Equal(legRctBytes, lReceiptConsensusEnc) { - t.Errorf("legacy receipt encoding (%x) does not match the expected consensus encoding (%x)", legRctBytes, lReceiptConsensusEnc) - } - - alRctWriter := new(bytes.Buffer) - if err := rct.Encode(accessListReceiptNode, alRctWriter); err != nil { - t.Fatalf("unable to encode access list receipt into writer: %v", err) +func testLogEncoding(t *testing.T) { + logWriter := new(bytes.Buffer) + if err := rct.Encode(logNode, logWriter); err != nil { + t.Fatalf("unable to encode log into writer: %v", err) } - alRctBytes := alRctWriter.Bytes() - if !bytes.Equal(alRctBytes, alReceiptConsensusEnc) { - t.Errorf("access list receipt encoding (%x) does not match the expected consensus encoding (%x)", alRctBytes, alReceiptConsensusEnc) + logBytes := logWriter.Bytes() + if !bytes.Equal(logBytes, logEncoding) { + t.Errorf("log encoding (%x) does not match the expected consensus encoding (%x)", logBytes, logEncoding) } } diff --git a/rct/rct_test.go b/rct/rct_test.go index b0b6595..59abdf6 100644 --- a/rct/rct_test.go +++ b/rct/rct_test.go @@ -90,6 +90,7 @@ type Receipt struct { CumulativeGasUsed Uint Bloom Bloom Logs Logs + LogRootCID &TrieNode } type Receipts [Receipt] @@ -107,6 +108,7 @@ func TestReceiptCodec(t *testing.T) { } testReceiptDecoding(t) testAccessListReceiptNodeContents(t) + testDynamicFeeReceiptNodeContents(t) testLegacyReceiptNodeContents(t) testReceiptEncoding(t) } @@ -303,7 +305,7 @@ func verifySharedContent(t *testing.T, rctNode ipld.Node, rct *types.Receipt) { t.Fatalf("receipt log Topic should be of type Bytes: %v", err) } if !bytes.Equal(topicBy, currentTopic) { - t.Errorf("receipt log topic%d bytes (%x) does not match expected bytes (%x)", j, topicBy, currentTopic) + t.Errorf("receipt log topic%d (%x) does not match expected topic%d (%x)", j, topicBy, j, currentTopic) } } } @@ -327,4 +329,13 @@ func testReceiptEncoding(t *testing.T) { if !bytes.Equal(alRctBytes, alReceiptConsensusEnc) { t.Errorf("access list receipt encoding (%x) does not match the expected consensus encoding (%x)", alRctBytes, alReceiptConsensusEnc) } + + dfRctWriter := new(bytes.Buffer) + if err := rct.Encode(dynamicFeeReceiptNode, dfRctWriter); err != nil { + t.Fatalf("unable to encode access list receipt into writer: %v", err) + } + dfRctBytes := dfRctWriter.Bytes() + if !bytes.Equal(dfRctBytes, dfReceiptConsensusEnc) { + t.Errorf("dynamic fee receipt encoding (%x) does not match the expected consensus encoding (%x)", dfRctBytes, dfReceiptConsensusEnc) + } } diff --git a/tx/tx_test.go b/tx/tx_test.go index a0f608e..7f67d0c 100644 --- a/tx/tx_test.go +++ b/tx/tx_test.go @@ -430,4 +430,13 @@ func testTransactionEncoding(t *testing.T) { if !bytes.Equal(alTxBytes, alTxConsensusEnc) { t.Errorf("access list transaction encoding (%x) does not match the expected consensus encoding (%x)", alTxBytes, alTxConsensusEnc) } + + dfTxWriter := new(bytes.Buffer) + if err := tx.Encode(dynamicFeeTxNode, dfTxWriter); err != nil { + t.Fatalf("unable to encode access list transaction into writer: %v", err) + } + dfTxBytes := dfTxWriter.Bytes() + if !bytes.Equal(dfTxBytes, dfTxConsensusEnc) { + t.Errorf("dynamic fee transaction encoding (%x) does not match the expected consensus encoding (%x)", dfTxBytes, dfTxConsensusEnc) + } } From 798eed16a55753f074e9ba6eb81df02bf8b42873 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 10 Aug 2021 12:05:22 -0500 Subject: [PATCH 08/11] log trie marshaller and unmarshaller unit tests --- log/log_test.go | 8 +- log_trie/log_trie_test.go | 424 ++++++++++---------------------------- trie/marshal.go | 20 +- trie/unmarshal.go | 2 +- 4 files changed, 130 insertions(+), 324 deletions(-) diff --git a/log/log_test.go b/log/log_test.go index c0db63c..c550cfe 100644 --- a/log/log_test.go +++ b/log/log_test.go @@ -17,12 +17,12 @@ var ( mockLog = &types.Log{ Address: common.BytesToAddress([]byte{0x11}), Topics: []common.Hash{common.HexToHash("hello"), common.HexToHash("moon"), common.HexToHash("goodbye"), common.HexToHash("world")}, - Data: []byte{0x01, 0x00, 0xff, 0x01, 0x00, 0xff, 0x01, 0x00, 0xff, 0x01, 0x00, 0xff, 0x01, 0x00, 0xff, 0x01, - 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, - 0x03, 0x02, 0x01, 0x03, 0x02, 0x01, 0x03, 0x02, 0x01, 0x03, 0x02, 0x01, 0x03, 0x02, 0x01, 0x03}, + Data: []byte{0x01, 0x00, 0xff, 0x01, 0x00, 0xff, 0x01, 0x00, 0xff, 0x01, 0x00, 0xff, 0x01, 0x00, 0xff, 0x01, + 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, + 0x03, 0x02, 0x01, 0x03, 0x02, 0x01, 0x03, 0x02, 0x01, 0x03, 0x02, 0x01, 0x03, 0x02, 0x01, 0x03}, } logEncoding, _ = rlp.EncodeToBytes(mockLog) - logNode ipld.Node + logNode ipld.Node ) /* IPLD Schemas diff --git a/log_trie/log_trie_test.go b/log_trie/log_trie_test.go index 3eeb59e..a475bff 100644 --- a/log_trie/log_trie_test.go +++ b/log_trie/log_trie_test.go @@ -2,7 +2,6 @@ package log_trie_test import ( "bytes" - "encoding/binary" "fmt" "strconv" "strings" @@ -23,67 +22,34 @@ import ( ) var ( - mockHash = crypto.Keccak256([]byte{1, 2, 3, 4, 5}) - legacyReceipt = &types.Receipt{ - Status: types.ReceiptStatusSuccessful, - CumulativeGasUsed: 1, - Logs: []*types.Log{ - { - Address: common.BytesToAddress([]byte{0x11}), - Topics: []common.Hash{common.HexToHash("hello"), common.HexToHash("world")}, - Data: []byte{0x01, 0x00, 0xff}, - }, - { - Address: common.BytesToAddress([]byte{0x01, 0x11}), - Topics: []common.Hash{common.HexToHash("goodbye"), common.HexToHash("world")}, - Data: []byte{0x01, 0x00, 0xff}, - }, - }, - Type: types.LegacyTxType, - } - accessListReceipt = &types.Receipt{ - PostState: mockHash, - CumulativeGasUsed: 1, - Logs: []*types.Log{ - { - Address: common.BytesToAddress([]byte{0x11}), - Topics: []common.Hash{common.HexToHash("hello"), common.HexToHash("world")}, - Data: []byte{0x01, 0x00, 0xff}, - }, - { - Address: common.BytesToAddress([]byte{0x01, 0x11}), - Topics: []common.Hash{common.HexToHash("goodbye"), common.HexToHash("world")}, - Data: []byte{0x01, 0x00, 0xff}, - }, - }, - Type: types.AccessListTxType, - } - mockLegacyReceiptLeafVal, _ = legacyReceipt.MarshalBinary() - mockALReceiptLeafVal, _ = accessListReceipt.MarshalBinary() - mockLeafParitalPath = common.Hex2Bytes("3114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45") - mockDecodedLeafPartialPath = shared.CompactToHex(mockLeafParitalPath) - mockLeafNodeLegacyReceipt = []interface{}{ + mockLog = &types.Log{ + Address: common.BytesToAddress([]byte{0x11}), + Topics: []common.Hash{common.HexToHash("hello"), common.HexToHash("moon"), common.HexToHash("goodbye"), common.HexToHash("world")}, + Data: []byte{0x01, 0x00, 0xff, 0x01, 0x00, 0xff, 0x01, 0x00, 0xff, 0x01, 0x00, 0xff, 0x01, 0x00, 0xff, 0x01, + 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, + 0x03, 0x02, 0x01, 0x03, 0x02, 0x01, 0x03, 0x02, 0x01, 0x03, 0x02, 0x01, 0x03, 0x02, 0x01, 0x03}, + } + mockLogVal, _ = rlp.EncodeToBytes(mockLog) + mockLeafParitalPath = common.Hex2Bytes("3114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45") + mockDecodedLeafPartialPath = shared.CompactToHex(mockLeafParitalPath) + mockLeafNode = []interface{}{ mockLeafParitalPath, - mockLegacyReceiptLeafVal, + mockLogVal, } - mockLeafNodeALReceipt = []interface{}{ - mockLeafParitalPath, - mockALReceiptLeafVal, - } - mockLeafNodeRLPLegacyReceipt, _ = rlp.EncodeToBytes(mockLeafNodeLegacyReceipt) - mockLeafNodeRLPALReceipt, _ = rlp.EncodeToBytes(mockLeafNodeALReceipt) + mockLeafNodeRLP, _ = rlp.EncodeToBytes(mockLeafNode) mockExtensionPartialPath = common.Hex2Bytes("1114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45") mockDecodedExtensionPartialPath = shared.CompactToHex(mockExtensionPartialPath) - mockExtensionHash = crypto.Keccak256(mockLeafNodeRLPLegacyReceipt) + mockExtensionHash = crypto.Keccak256(mockLeafNodeRLP) mockExtensionNode = []interface{}{ mockExtensionPartialPath, mockExtensionHash, } mockExtensionNodeRLP, _ = rlp.EncodeToBytes(mockExtensionNode) - mockChild0 = crypto.Keccak256([]byte{0}) - mockChild5 = crypto.Keccak256([]byte{5}) - mockChildE = crypto.Keccak256([]byte{14}) - mockBranchNode = []interface{}{ + + mockChild0 = crypto.Keccak256([]byte{0}) + mockChild5 = crypto.Keccak256([]byte{5}) + mockChildE = crypto.Keccak256([]byte{14}) + mockBranchNode = []interface{}{ mockChild0, []byte{}, []byte{}, @@ -100,11 +66,11 @@ var ( []byte{}, mockChildE, []byte{}, - mockLegacyReceiptLeafVal, + mockLogVal, } mockBranchNodeRLP, _ = rlp.EncodeToBytes(mockBranchNode) - leafNodeLegacy, leafNodeAL, extensionNode, branchNode ipld.Node + leafNode, extensionNode, branchNode ipld.Node ) /* IPLD Schemas @@ -163,98 +129,76 @@ type Log struct { Topics Topics Data Bytes } - -type Logs [Log] - -type Receipt struct { - TxType TxType - // We could make Status an enum - Status Uint // nullable - PostState Hash // nullable - CumulativeGasUsed Uint - Bloom Bloom - Logs Logs -} - -type Receipts [Receipt] */ -func TestReceiptTrieCodec(t *testing.T) { - testReceiptTrieDecode(t) - testReceiptTrieNodeContents(t) - testReceiptTrieEncode(t) +func TestLogTrieCodec(t *testing.T) { + testLogTrieDecode(t) + testLogTrieNodeContents(t) + testLogTrieEncode(t) } -func testReceiptTrieDecode(t *testing.T) { +func testLogTrieDecode(t *testing.T) { branchNodeBuilder := dageth.Type.TrieNode.NewBuilder() branchNodeReader := bytes.NewReader(mockBranchNodeRLP) if err := rct_trie.Decode(branchNodeBuilder, branchNodeReader); err != nil { - t.Fatalf("unable to decode receipt trie branch node into an IPLD node: %v", err) + t.Fatalf("unable to decode log trie branch node into an IPLD node: %v", err) } branchNode = branchNodeBuilder.Build() extensionNodeBuilder := dageth.Type.TrieNode.NewBuilder() extensionNodeReader := bytes.NewReader(mockExtensionNodeRLP) if err := rct_trie.Decode(extensionNodeBuilder, extensionNodeReader); err != nil { - t.Fatalf("unable to decode receipt trie extension node into an IPLD node: %v", err) + t.Fatalf("unable to decode log trie extension node into an IPLD node: %v", err) } extensionNode = extensionNodeBuilder.Build() - leafNodeBuilderLegacy := dageth.Type.TrieNode.NewBuilder() - leafNodeReaderLegacy := bytes.NewReader(mockLeafNodeRLPLegacyReceipt) - if err := rct_trie.Decode(leafNodeBuilderLegacy, leafNodeReaderLegacy); err != nil { - t.Fatalf("unable to decode receipt trie leaf node into an IPLD node: %v", err) + leafNodeBuilder := dageth.Type.TrieNode.NewBuilder() + leafNodeReader := bytes.NewReader(mockLeafNodeRLP) + if err := rct_trie.Decode(leafNodeBuilder, leafNodeReader); err != nil { + t.Fatalf("unable to decode log trie leaf node into an IPLD node: %v", err) } - leafNodeLegacy = leafNodeBuilderLegacy.Build() - - leafNodeBuilderAL := dageth.Type.TrieNode.NewBuilder() - leafNodeReaderAL := bytes.NewReader(mockLeafNodeRLPALReceipt) - if err := rct_trie.Decode(leafNodeBuilderAL, leafNodeReaderAL); err != nil { - t.Fatalf("unable to decode receipt trie leaf node into an IPLD node: %v", err) - } - leafNodeAL = leafNodeBuilderAL.Build() + leafNode = leafNodeBuilder.Build() } -func testReceiptTrieNodeContents(t *testing.T) { +func testLogTrieNodeContents(t *testing.T) { verifyBranchNodeContents(t) verifyExtensionNodeContents(t) - verifyLegacyReceiptLeafNodeContents(t) - verifyALReceiptLeafNodeContents(t) + verifyLeafNodeContents(t) } func verifyBranchNodeContents(t *testing.T) { branch, err := branchNode.LookupByString(trie.BRANCH_NODE.String()) if err != nil { - t.Fatalf("receipt trie branch node missing enum key: %v", err) + t.Fatalf("log trie branch node missing enum key: %v", err) } nullChildren := []int{1, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 15} for _, i := range nullChildren { key := fmt.Sprintf("Child%s", strings.ToUpper(strconv.FormatInt(int64(i), 16))) childNode, err := branch.LookupByString(key) if err != nil { - t.Fatalf("receipt trie branch node missing %s: %v", key, err) + t.Fatalf("log trie branch node missing %s: %v", key, err) } if !childNode.IsNull() { - t.Errorf("receipt trie branch node %s should be null", key) + t.Errorf("log trie branch node %s should be null", key) } } child0Node, err := branch.LookupByString("Child0") if err != nil { - t.Fatalf("receipt trie branch node missing Child0: %v", err) + t.Fatalf("log trie branch node missing Child0: %v", err) } // Why do we have to look up the Union as if it is keyed representation? // It is kinded, we ought to be able to assert the node to a Link (call .AsLink on child0Node) child0LinkNode, err := child0Node.LookupByString("Link") if err != nil { - t.Fatalf("receipt trie branch node Child0 should be of type Link: %v", err) + t.Fatalf("log trie branch node Child0 should be of type Link: %v", err) } child0Link, err := child0LinkNode.AsLink() if err != nil { - t.Fatalf("receipt trie branch node Child0 should be of type Link: %v", err) + t.Fatalf("log trie branch node Child0 should be of type Link: %v", err) } child0CIDLink, ok := child0Link.(cidlink.Link) if !ok { - t.Fatalf("receipt trie branch node Child0 should be a CID: %v", err) + t.Fatalf("log trie branch node Child0 should be a CID: %v", err) } child0Mh := child0CIDLink.Hash() decodedChild0Mh, err := multihash.Decode(child0Mh) @@ -262,24 +206,24 @@ func verifyBranchNodeContents(t *testing.T) { t.Fatalf("could not decode branch node Child0 multihash: %v", err) } if !bytes.Equal(decodedChild0Mh.Digest, mockChild0) { - t.Errorf("receipt trie branch node child0 hash (%x) does not match expected hash (%d)", decodedChild0Mh.Digest, mockChild0) + t.Errorf("log trie branch node child0 hash (%x) does not match expected hash (%d)", decodedChild0Mh.Digest, mockChild0) } child5Node, err := branch.LookupByString("Child5") if err != nil { - t.Fatalf("receipt trie branch node missing Child5: %v", err) + t.Fatalf("log trie branch node missing Child5: %v", err) } child5LinkNode, err := child5Node.LookupByString("Link") if err != nil { - t.Fatalf("receipt trie branch node Child5 should be of type Link: %v", err) + t.Fatalf("log trie branch node Child5 should be of type Link: %v", err) } child5Link, err := child5LinkNode.AsLink() if err != nil { - t.Fatalf("receipt trie branch node Child5 should be of type Link: %v", err) + t.Fatalf("log trie branch node Child5 should be of type Link: %v", err) } child5CIDLink, ok := child5Link.(cidlink.Link) if !ok { - t.Fatalf("receipt trie branch node Child5 should be a CID: %v", err) + t.Fatalf("log trie branch node Child5 should be a CID: %v", err) } child5Mh := child5CIDLink.Hash() decodedChild5Mh, err := multihash.Decode(child5Mh) @@ -287,24 +231,24 @@ func verifyBranchNodeContents(t *testing.T) { t.Fatalf("could not decode branch node Child5 multihash: %v", err) } if !bytes.Equal(decodedChild5Mh.Digest, mockChild5) { - t.Errorf("receipt trie branch node child5 hash (%x) does not match expected hash (%d)", decodedChild5Mh.Digest, mockChild0) + t.Errorf("log trie branch node child5 hash (%x) does not match expected hash (%d)", decodedChild5Mh.Digest, mockChild0) } childENode, err := branch.LookupByString("ChildE") if err != nil { - t.Fatalf("receipt trie branch node missing ChildE: %v", err) + t.Fatalf("log trie branch node missing ChildE: %v", err) } childELinkNode, err := childENode.LookupByString("Link") if err != nil { - t.Fatalf("receipt trie branch node ChildE should be of type Link: %v", err) + t.Fatalf("log trie branch node ChildE should be of type Link: %v", err) } childELink, err := childELinkNode.AsLink() if err != nil { - t.Fatalf("receipt trie branch node ChildE should be of type Link: %v", err) + t.Fatalf("log trie branch node ChildE should be of type Link: %v", err) } childECIDLink, ok := childELink.(cidlink.Link) if !ok { - t.Fatalf("receipt trie branch node ChildE should be a CID: %v", err) + t.Fatalf("log trie branch node ChildE should be a CID: %v", err) } childEMh := childECIDLink.Hash() decodedChildEMh, err := multihash.Decode(childEMh) @@ -312,311 +256,165 @@ func verifyBranchNodeContents(t *testing.T) { t.Fatalf("could not decode branch node ChildE multihash: %v", err) } if !bytes.Equal(decodedChildEMh.Digest, mockChildE) { - t.Errorf("receipt trie branch node childE hash (%x) does not match expected hash (%d)", decodedChildEMh.Digest, mockChild0) + t.Errorf("log trie branch node childE hash (%x) does not match expected hash (%d)", decodedChildEMh.Digest, mockChild0) } valEnumNode, err := branch.LookupByString("Value") if err != nil { - t.Fatalf("receipt trie branch node missing Value: %v", err) + t.Fatalf("log trie branch node missing Value: %v", err) } - verifyLegacyReceiptLeafValue(valEnumNode, t) + verifyLeafValue(valEnumNode, t) } func verifyExtensionNodeContents(t *testing.T) { ext, err := extensionNode.LookupByString(trie.EXTENSION_NODE.String()) if err != nil { - t.Fatalf("receipt trie extension node missing enum key: %v", err) + t.Fatalf("log trie extension node missing enum key: %v", err) } extPathNode, err := ext.LookupByString("PartialPath") if err != nil { - t.Fatalf("receipt trie extension node missing PartialPath: %v", err) + t.Fatalf("log trie extension node missing PartialPath: %v", err) } extPathBytes, err := extPathNode.AsBytes() if err != nil { - t.Fatalf("receipt trie extension node PartialPath should be of type Bytes: %v", err) + t.Fatalf("log trie extension node PartialPath should be of type Bytes: %v", err) } if !bytes.Equal(extPathBytes, mockDecodedExtensionPartialPath) { - t.Errorf("receipt trie extension node partial path (%x) does not match expected partial path (%x)", extPathBytes, mockExtensionPartialPath) + t.Errorf("log trie extension node partial path (%x) does not match expected partial path (%x)", extPathBytes, mockExtensionPartialPath) } childNode, err := ext.LookupByString("Child") if err != nil { - t.Fatalf("receipt trie extension node missing Child: %v", err) + t.Fatalf("log trie extension node missing Child: %v", err) } childLinkNode, err := childNode.LookupByString("Link") if err != nil { - t.Fatalf("receipt trie extension node Child should be of kind Link: %v", err) + t.Fatalf("log trie extension node Child should be of kind Link: %v", err) } childLink, err := childLinkNode.AsLink() if err != nil { - t.Fatalf("receipt trie extension node Child should be of kind Link: %v", err) + t.Fatalf("log trie extension node Child should be of kind Link: %v", err) } childCIDLink, ok := childLink.(cidlink.Link) if !ok { - t.Fatalf("receipt trie extension node Child is not a CID: %v", err) + t.Fatalf("log trie extension node Child is not a CID: %v", err) } childMh := childCIDLink.Hash() decodedChildMh, err := multihash.Decode(childMh) if err != nil { - t.Fatalf("receipt trie extension node Child could not be decoded into multihash: %v", err) + t.Fatalf("log trie extension node Child could not be decoded into multihash: %v", err) } if !bytes.Equal(decodedChildMh.Digest, mockExtensionHash) { - t.Errorf("receipt trie extension node child hash (%x) does not match expected hash (%x)", decodedChildMh.Digest, mockExtensionHash) - } -} - -func verifyALReceiptLeafNodeContents(t *testing.T) { - leaf, err := leafNodeAL.LookupByString(trie.LEAF_NODE.String()) - if err != nil { - t.Fatalf("unable to resolve TrieNode union to a leaf: %v", err) - } - - leafPathNode, err := leaf.LookupByString("PartialPath") - if err != nil { - t.Fatalf("receipt trie leaf node missing PartialPath: %v", err) - } - leafPathBytes, err := leafPathNode.AsBytes() - if err != nil { - t.Fatalf("receipt trie leaf node PartialPath should be of type Bytes: %v", err) - } - - if !bytes.Equal(leafPathBytes, mockDecodedLeafPartialPath) { - t.Errorf("receipt trie leaf node partial path (%x) does not match expected partial path (%x)", leafPathBytes, mockDecodedLeafPartialPath) + t.Errorf("log trie extension node child hash (%x) does not match expected hash (%x)", decodedChildMh.Digest, mockExtensionHash) } - - valEnumNode, err := leaf.LookupByString("Value") - if err != nil { - t.Fatalf("receipt trie leaf node missing Value: %v", err) - } - verifyALReceiptLeafValue(valEnumNode, t) } -func verifyLegacyReceiptLeafNodeContents(t *testing.T) { - leaf, err := leafNodeLegacy.LookupByString(trie.LEAF_NODE.String()) +func verifyLeafNodeContents(t *testing.T) { + leaf, err := leafNode.LookupByString(trie.LEAF_NODE.String()) if err != nil { t.Fatalf("unable to resolve TrieNode union to a leaf: %v", err) } leafPathNode, err := leaf.LookupByString("PartialPath") if err != nil { - t.Fatalf("receipt trie leaf node missing PartialPath: %v", err) + t.Fatalf("log trie leaf node missing PartialPath: %v", err) } leafPathBytes, err := leafPathNode.AsBytes() if err != nil { - t.Fatalf("receipt trie leaf node PartialPath should be of type Bytes: %v", err) + t.Fatalf("log trie leaf node PartialPath should be of type Bytes: %v", err) } if !bytes.Equal(leafPathBytes, mockDecodedLeafPartialPath) { - t.Errorf("receipt trie leaf node partial path (%x) does not match expected partial path (%x)", leafPathBytes, mockDecodedLeafPartialPath) + t.Errorf("log trie leaf node partial path (%x) does not match expected partial path (%x)", leafPathBytes, mockDecodedLeafPartialPath) } valEnumNode, err := leaf.LookupByString("Value") if err != nil { - t.Fatalf("receipt trie leaf node missing Value: %v", err) - } - verifyLegacyReceiptLeafValue(valEnumNode, t) -} - -func verifyALReceiptLeafValue(valEnumNode ipld.Node, t *testing.T) { - rctNode, err := valEnumNode.LookupByString(trie.RCT_VALUE.String()) - if err != nil { - t.Fatalf("unable to resolve Value union to a receipt: %v", err) - } - - verifySharedContent(t, rctNode, accessListReceipt) - statusNode, err := rctNode.LookupByString("Status") - if err != nil { - t.Fatalf("receipt is missing Status: %v", err) - } - if !statusNode.IsNull() { - t.Fatalf("receipt Status should be null") - } - - postStateNode, err := rctNode.LookupByString("PostState") - if err != nil { - t.Fatalf("receipt is missing PostState: %v", err) - } - if postStateNode.IsNull() { - t.Errorf("receipt PostState should not be null") - } - postStateBy, err := postStateNode.AsBytes() - if err != nil { - t.Fatalf("receipt PostState should be of type Bytes: %v", err) - } - if !bytes.Equal(postStateBy, accessListReceipt.PostState) { - t.Errorf("receipt post state (%d) does not match expected post state (%d)", postStateBy, accessListReceipt.PostState) - } -} - -func verifyLegacyReceiptLeafValue(valEnumNode ipld.Node, t *testing.T) { - rctNode, err := valEnumNode.LookupByString(trie.RCT_VALUE.String()) - if err != nil { - t.Fatalf("unable to resolve Value union to a receipt: %v", err) - } - - verifySharedContent(t, rctNode, legacyReceipt) - statusNode, err := rctNode.LookupByString("Status") - if err != nil { - t.Fatalf("receipt is missing Status: %v", err) - } - if statusNode.IsNull() { - t.Fatalf("receipt Status should not be null") - } - statusBy, err := statusNode.AsBytes() - if err != nil { - t.Fatalf("receipt Status should be of type Bytes: %v", err) - } - status := binary.BigEndian.Uint64(statusBy) - if status != legacyReceipt.Status { - t.Errorf("receipt status (%d) does not match expected status (%d)", status, legacyReceipt.Status) - } - - postStateNode, err := rctNode.LookupByString("PostState") - if err != nil { - t.Fatalf("receipt is missing PostState: %v", err) - } - if !postStateNode.IsNull() { - t.Errorf("receipt PostState should be null") + t.Fatalf("log trie leaf node missing Value: %v", err) } + verifyLeafValue(valEnumNode, t) } -func verifySharedContent(t *testing.T, rctNode ipld.Node, rct *types.Receipt) { - typeNode, err := rctNode.LookupByString("TxType") - if err != nil { - t.Fatalf("receipt is missing TxType: %v", err) - } - typeBy, err := typeNode.AsBytes() +func verifyLeafValue(valEnumNode ipld.Node, t *testing.T) { + logNode, err := valEnumNode.LookupByString(trie.LOG_VALUE.String()) if err != nil { - t.Fatalf("receipt TxType should be of type Bytes: %v", err) - } - if len(typeBy) != 1 { - t.Fatalf("receipt TxType should be a single byte") - } - if typeBy[0] != rct.Type { - t.Errorf("receipt tx type (%d) does not match expected tx type (%d)", typeBy[0], rct.Type) + t.Fatalf("unable to resolve Value union to a log: %v", err) } - cguNode, err := rctNode.LookupByString("CumulativeGasUsed") + addressNode, err := logNode.LookupByString("Address") if err != nil { - t.Fatalf("receipt is missing CumulativeGasUsed: %v", err) + t.Fatalf("log is missing Address: %v", err) } - cguBy, err := cguNode.AsBytes() + addrBytes, err := addressNode.AsBytes() if err != nil { - t.Fatalf("receipt CumulativeGasUsed should be of type Bytes: %v", err) + t.Fatalf("log Address should be of type Bytes") } - cgu := binary.BigEndian.Uint64(cguBy) - if cgu != rct.CumulativeGasUsed { - t.Errorf("receipt cumulative gas used (%d) does not match expected cumulative gas used (%d)", cgu, rct.CumulativeGasUsed) + if !bytes.Equal(addrBytes, mockLog.Address.Bytes()) { + t.Errorf("log Address (%x) does not match expected Address (%x)", addrBytes, mockLog.Address.Bytes()) } - bloomNode, err := rctNode.LookupByString("Bloom") + dataNode, err := logNode.LookupByString("data") if err != nil { - t.Fatalf("receipt is missing Bloom: %v", err) + t.Fatalf("log is missing Data: %v", err) } - bloomBy, err := bloomNode.AsBytes() + data, err := dataNode.AsBytes() if err != nil { - t.Fatalf("receipt Bloom should be of type Bytes: %v", err) + t.Fatalf("log Data should be of type Bytes") } - if !bytes.Equal(bloomBy, rct.Bloom.Bytes()) { - t.Errorf("receipt bloom (%x) does not match expected bloom (%x)", bloomBy, rct.Bloom.Bytes()) + if !bytes.Equal(data, mockLog.Data) { + t.Errorf("log Data (%x) does not match expected data (%x)", data, mockLog.Data) } - logsNode, err := rctNode.LookupByString("Logs") + topicsNode, err := logNode.LookupByString("Topics") if err != nil { - t.Fatalf("receipt is missing Logs: %v", err) + t.Fatalf("log is missing Topics: %v", err) } - if logsNode.Length() != int64(len(rct.Logs)) { - t.Fatalf("receipt should have %d logs", len(rct.Logs)) + if topicsNode.Length() != 4 { + t.Fatal("log should have two topics") } - logsLI := logsNode.ListIterator() - for !logsLI.Done() { - i, logNode, err := logsLI.Next() + topicsLI := topicsNode.ListIterator() + for !topicsLI.Done() { + j, topicNode, err := topicsLI.Next() if err != nil { - t.Fatalf("receipt log iterator error: %v", err) + t.Fatalf("receipt log topic iterator error: %v", err) } - currentLog := rct.Logs[i] - addrNode, err := logNode.LookupByString("Address") + currentTopic := mockLog.Topics[j].Bytes() + topicBy, err := topicNode.AsBytes() if err != nil { - t.Fatalf("receipt log is missing Address: %v", err) + t.Fatalf("log Topic should be of type Bytes: %v", err) } - addrBy, err := addrNode.AsBytes() - if err != nil { - t.Fatalf("receipt log Address should be of type Bytes: %v", err) - } - if !bytes.Equal(addrBy, currentLog.Address.Bytes()) { - t.Errorf("receipt log address (%x) does not match expected address (%x)", addrBy, currentLog.Address.Bytes()) - } - dataNode, err := logNode.LookupByString("Data") - if err != nil { - t.Fatalf("receipt log is missing Data: %v", err) - } - data, err := dataNode.AsBytes() - if err != nil { - t.Fatalf("receipt log Data should be of type Bytes: %v", err) - } - if !bytes.Equal(data, currentLog.Data) { - t.Errorf("receipt log data (%x) does not match expected data (%x)", data, currentLog.Data) - } - topicsNode, err := logNode.LookupByString("Topics") - if err != nil { - t.Fatalf("receipt log is missing Topics: %v", err) - } - if topicsNode.Length() != 2 { - t.Fatal("receipt log should have two topics") - } - topicsLI := topicsNode.ListIterator() - for !topicsLI.Done() { - j, topicNode, err := topicsLI.Next() - if err != nil { - t.Fatalf("receipt log topic iterator error: %v", err) - } - currentTopic := currentLog.Topics[j].Bytes() - topicBy, err := topicNode.AsBytes() - if err != nil { - t.Fatalf("receipt log Topic should be of type Bytes: %v", err) - } - if !bytes.Equal(topicBy, currentTopic) { - t.Errorf("receipt log topic%d bytes (%x) does not match expected bytes (%x)", j, topicBy, currentTopic) - } + if !bytes.Equal(topicBy, currentTopic) { + t.Errorf("log topic%d (%x) does not match expected topic%d (%x)", j, topicBy, j, currentTopic) } } } -func testReceiptTrieEncode(t *testing.T) { +func testLogTrieEncode(t *testing.T) { branchWriter := new(bytes.Buffer) if err := rct_trie.Encode(branchNode, branchWriter); err != nil { - t.Fatalf("unable to encode receipt trie branch node into writer: %v", err) + t.Fatalf("unable to encode log trie branch node into writer: %v", err) } encodedBranchBytes := branchWriter.Bytes() if !bytes.Equal(encodedBranchBytes, mockBranchNodeRLP) { - t.Errorf("receipt trie branch node encoding (%x) does not match the expected consensus encoding (%x)", encodedBranchBytes, mockBranchNodeRLP) + t.Errorf("log trie branch node encoding (%x) does not match the expected consensus encoding (%x)", encodedBranchBytes, mockBranchNodeRLP) } extensionWriter := new(bytes.Buffer) if err := rct_trie.Encode(extensionNode, extensionWriter); err != nil { - t.Fatalf("unable to encode receipt trie extension node into writer: %v", err) + t.Fatalf("unable to encode log trie extension node into writer: %v", err) } encodedExtensionBytes := extensionWriter.Bytes() if !bytes.Equal(encodedExtensionBytes, mockExtensionNodeRLP) { - t.Errorf("receipt trie extension node encoding (%x) does not match the expected consensus encoding (%x)", encodedExtensionBytes, mockExtensionNodeRLP) - } - - leafWriterLegacyReceipt := new(bytes.Buffer) - if err := rct_trie.Encode(leafNodeLegacy, leafWriterLegacyReceipt); err != nil { - t.Fatalf("unable to encode receipt trie leaf node into writer: %v", err) - } - encodedLeafBytesLegacyReceipt := leafWriterLegacyReceipt.Bytes() - if !bytes.Equal(encodedLeafBytesLegacyReceipt, mockLeafNodeRLPLegacyReceipt) { - t.Errorf("receipt trie leaf node encoding (%x) does not match the expected consenus encoding (%x)", encodedLeafBytesLegacyReceipt, mockLeafNodeRLPLegacyReceipt) + t.Errorf("log trie extension node encoding (%x) does not match the expected consensus encoding (%x)", encodedExtensionBytes, mockExtensionNodeRLP) } - leafWriterALReceipt := new(bytes.Buffer) - if err := rct_trie.Encode(leafNodeAL, leafWriterALReceipt); err != nil { - t.Fatalf("unable to encode receipt trie leaf node into writer: %v", err) + leafWriter := new(bytes.Buffer) + if err := rct_trie.Encode(leafNode, leafWriter); err != nil { + t.Fatalf("unable to encode log trie leaf node into writer: %v", err) } - encodedLeafBytesALReceipt := leafWriterALReceipt.Bytes() - if !bytes.Equal(encodedLeafBytesALReceipt, mockLeafNodeRLPALReceipt) { - t.Errorf("receipt trie leaf node encoding (%x) does not match the expected consenus encoding (%x)", encodedLeafBytesALReceipt, mockLeafNodeRLPALReceipt) + encodedLeafBytes := leafWriter.Bytes() + if !bytes.Equal(encodedLeafBytes, mockLeafNodeRLP) { + t.Errorf("log trie leaf node encoding (%x) does not match the expected consenus encoding (%x)", encodedLeafBytes, mockLeafNodeRLP) } } diff --git a/trie/marshal.go b/trie/marshal.go index e84d0c5..f3cc045 100644 --- a/trie/marshal.go +++ b/trie/marshal.go @@ -7,16 +7,18 @@ import ( "strconv" "strings" + "github.com/vulcanize/go-codec-dageth/log" + "github.com/ethereum/go-ethereum/rlp" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" "github.com/multiformats/go-multihash" dageth "github.com/vulcanize/go-codec-dageth" - dageth_rct "github.com/vulcanize/go-codec-dageth/rct" + "github.com/vulcanize/go-codec-dageth/rct" "github.com/vulcanize/go-codec-dageth/shared" - dageth_account "github.com/vulcanize/go-codec-dageth/state_account" - dageth_tx "github.com/vulcanize/go-codec-dageth/tx" + account "github.com/vulcanize/go-codec-dageth/state_account" + "github.com/vulcanize/go-codec-dageth/tx" ) type NodeKind string @@ -263,24 +265,30 @@ func packValue(node ipld.Node) ([]byte, error) { switch valKind { case TX_VALUE: buf := new(bytes.Buffer) - if err := dageth_tx.Encode(valNode, buf); err != nil { + if err := tx.Encode(valNode, buf); err != nil { return nil, err } return buf.Bytes(), nil case RCT_VALUE: buf := new(bytes.Buffer) - if err := dageth_rct.Encode(valNode, buf); err != nil { + if err := rct.Encode(valNode, buf); err != nil { return nil, err } return buf.Bytes(), nil case STATE_VALUE: buf := new(bytes.Buffer) - if err := dageth_account.Encode(valNode, buf); err != nil { + if err := account.Encode(valNode, buf); err != nil { return nil, err } return buf.Bytes(), nil case STORAGE_VALUE: return valNode.AsBytes() + case LOG_VALUE: + buf := new(bytes.Buffer) + if err := log.Encode(valNode, buf); err != nil { + return nil, err + } + return buf.Bytes(), nil default: return nil, fmt.Errorf("eth trie value of unexpected kind %s", valKind.String()) } diff --git a/trie/unmarshal.go b/trie/unmarshal.go index df279e0..2ac708f 100644 --- a/trie/unmarshal.go +++ b/trie/unmarshal.go @@ -17,7 +17,7 @@ import ( "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" "github.com/vulcanize/go-codec-dageth/rct" - "github.com/vulcanize/go-codec-dageth/state_account" + account "github.com/vulcanize/go-codec-dageth/state_account" "github.com/vulcanize/go-codec-dageth/tx" ) From d5054b0c6bb74f128b1ea2d020d79b7af0905878 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 10 Aug 2021 12:06:09 -0500 Subject: [PATCH 09/11] update code gen output --- ipldsch_satisfaction.go | 194 +++++++++++++++++++++++++++------------- ipldsch_types.go | 7 +- 2 files changed, 136 insertions(+), 65 deletions(-) diff --git a/ipldsch_satisfaction.go b/ipldsch_satisfaction.go index b08d31d..534c9d8 100644 --- a/ipldsch_satisfaction.go +++ b/ipldsch_satisfaction.go @@ -4031,7 +4031,7 @@ type _Child__Assembler struct { cm schema.Maybe ca1 _Link__Assembler - ca2 *_TrieNode__Assembler + ca2 _TrieNode__Assembler ca uint } @@ -4181,7 +4181,7 @@ func (ma *_Child__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, error) ma.w.tag = 2 ma.ca2.w = &ma.w.x2 ma.ca2.m = &ma.cm - return ma.ca2, nil + return &ma.ca2, nil } return nil, ipld.ErrInvalidKey{TypeName: "dageth.Child", Key: &_String{k}} } @@ -4218,17 +4218,14 @@ func (ma *_Child__Assembler) AssembleValue() ipld.NodeAssembler { } ma.state = maState_midValue switch ma.ca { - case 1: + case 0: ma.ca1.w = &ma.w.x1 ma.ca1.m = &ma.cm return &ma.ca1 - case 2: - if ma.ca2 == nil { - ma.ca2 = &_TrieNode__Assembler{} - } + case 1: ma.ca2.w = &ma.w.x2 ma.ca2.m = &ma.cm - return ma.ca2 + return &ma.ca2 default: panic("unreachable") } @@ -4454,7 +4451,7 @@ type _Child__ReprAssembler struct { w *_Child m *schema.Maybe ca1 _Link__ReprAssembler - ca2 *_TrieNode__ReprAssembler + ca2 _TrieNode__ReprAssembler ca uint } @@ -4483,9 +4480,6 @@ func (na *_Child__ReprAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, er } na.ca = 2 na.w.tag = 2 - if na.ca2 == nil { - na.ca2 = &_TrieNode__ReprAssembler{} - } na.ca2.w = &na.w.x2 na.ca2.m = na.m return na.ca2.BeginMap(sizeHint) @@ -9058,6 +9052,9 @@ func (n _Receipt) FieldBloom() Bloom { func (n _Receipt) FieldLogs() Logs { return &n.Logs } +func (n _Receipt) FieldLogRootCID() Link { + return &n.LogRootCID +} type _Receipt__Maybe struct { m schema.Maybe @@ -9100,6 +9097,7 @@ var ( fieldName__Receipt_CumulativeGasUsed = _String{"CumulativeGasUsed"} fieldName__Receipt_Bloom = _String{"Bloom"} fieldName__Receipt_Logs = _String{"Logs"} + fieldName__Receipt_LogRootCID = _String{"LogRootCID"} ) var _ ipld.Node = (Receipt)(&_Receipt{}) var _ schema.TypedNode = (Receipt)(&_Receipt{}) @@ -9127,6 +9125,8 @@ func (n Receipt) LookupByString(key string) (ipld.Node, error) { return &n.Bloom, nil case "Logs": return &n.Logs, nil + case "LogRootCID": + return &n.LogRootCID, nil default: return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} } @@ -9154,7 +9154,7 @@ type _Receipt__MapItr struct { } func (itr *_Receipt__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) { - if itr.idx >= 6 { + if itr.idx >= 7 { return nil, nil, ipld.ErrIteratorOverread{} } switch itr.idx { @@ -9184,6 +9184,9 @@ func (itr *_Receipt__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) { case 5: k = &fieldName__Receipt_Logs v = &itr.n.Logs + case 6: + k = &fieldName__Receipt_LogRootCID + v = &itr.n.LogRootCID default: panic("unreachable") } @@ -9191,14 +9194,14 @@ func (itr *_Receipt__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) { return } func (itr *_Receipt__MapItr) Done() bool { - return itr.idx >= 6 + return itr.idx >= 7 } func (Receipt) ListIterator() ipld.ListIterator { return nil } func (Receipt) Length() int64 { - return 6 + return 7 } func (Receipt) IsAbsent() bool { return false @@ -9266,6 +9269,7 @@ type _Receipt__Assembler struct { ca_CumulativeGasUsed _Uint__Assembler ca_Bloom _Bloom__Assembler ca_Logs _Logs__Assembler + ca_LogRootCID _Link__Assembler } func (na *_Receipt__Assembler) reset() { @@ -9277,6 +9281,7 @@ func (na *_Receipt__Assembler) reset() { na.ca_CumulativeGasUsed.reset() na.ca_Bloom.reset() na.ca_Logs.reset() + na.ca_LogRootCID.reset() } var ( @@ -9286,7 +9291,8 @@ var ( fieldBit__Receipt_CumulativeGasUsed = 1 << 3 fieldBit__Receipt_Bloom = 1 << 4 fieldBit__Receipt_Logs = 1 << 5 - fieldBits__Receipt_sufficient = 0 + 1<<0 + 1<<1 + 1<<2 + 1<<3 + 1<<4 + 1<<5 + fieldBit__Receipt_LogRootCID = 1 << 6 + fieldBits__Receipt_sufficient = 0 + 1<<0 + 1<<1 + 1<<2 + 1<<3 + 1<<4 + 1<<5 + 1<<6 ) func (na *_Receipt__Assembler) BeginMap(int64) (ipld.MapAssembler, error) { @@ -9442,6 +9448,16 @@ func (ma *_Receipt__Assembler) valueFinishTidy() bool { default: return false } + case 6: + switch ma.cm { + case schema.Maybe_Value: + ma.ca_LogRootCID.w = nil + ma.cm = schema.Maybe_Absent + ma.state = maState_initial + return true + default: + return false + } default: panic("unreachable") } @@ -9524,6 +9540,16 @@ func (ma *_Receipt__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, erro ma.ca_Logs.w = &ma.w.Logs ma.ca_Logs.m = &ma.cm return &ma.ca_Logs, nil + case "LogRootCID": + if ma.s&fieldBit__Receipt_LogRootCID != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__Receipt_LogRootCID} + } + ma.s += fieldBit__Receipt_LogRootCID + ma.state = maState_midValue + ma.f = 6 + ma.ca_LogRootCID.w = &ma.w.LogRootCID + ma.ca_LogRootCID.m = &ma.cm + return &ma.ca_LogRootCID, nil } return nil, ipld.ErrInvalidKey{TypeName: "dageth.Receipt", Key: &_String{k}} } @@ -9586,6 +9612,10 @@ func (ma *_Receipt__Assembler) AssembleValue() ipld.NodeAssembler { ma.ca_Logs.w = &ma.w.Logs ma.ca_Logs.m = &ma.cm return &ma.ca_Logs + case 6: + ma.ca_LogRootCID.w = &ma.w.LogRootCID + ma.ca_LogRootCID.m = &ma.cm + return &ma.ca_LogRootCID default: panic("unreachable") } @@ -9619,6 +9649,9 @@ func (ma *_Receipt__Assembler) Finish() error { if ma.s&fieldBit__Receipt_Logs == 0 { err.Missing = append(err.Missing, "Logs") } + if ma.s&fieldBit__Receipt_LogRootCID == 0 { + err.Missing = append(err.Missing, "LogRootCID") + } return err } ma.state = maState_finished @@ -9699,6 +9732,13 @@ func (ka *_Receipt__KeyAssembler) AssignString(k string) error { ka.s += fieldBit__Receipt_Logs ka.state = maState_expectValue ka.f = 5 + case "LogRootCID": + if ka.s&fieldBit__Receipt_LogRootCID != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__Receipt_LogRootCID} + } + ka.s += fieldBit__Receipt_LogRootCID + ka.state = maState_expectValue + ka.f = 6 default: return ipld.ErrInvalidKey{TypeName: "dageth.Receipt", Key: &_String{k}} } @@ -9736,6 +9776,7 @@ var ( fieldName__Receipt_CumulativeGasUsed_serial = _String{"CumulativeGasUsed"} fieldName__Receipt_Bloom_serial = _String{"Bloom"} fieldName__Receipt_Logs_serial = _String{"Logs"} + fieldName__Receipt_LogRootCID_serial = _String{"LogRootCID"} ) var _ ipld.Node = &_Receipt__Repr{} @@ -9762,6 +9803,8 @@ func (n *_Receipt__Repr) LookupByString(key string) (ipld.Node, error) { return n.Bloom.Representation(), nil case "Logs": return n.Logs.Representation(), nil + case "LogRootCID": + return n.LogRootCID.Representation(), nil default: return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} } @@ -9789,7 +9832,7 @@ type _Receipt__ReprMapItr struct { } func (itr *_Receipt__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) { - if itr.idx >= 6 { + if itr.idx >= 7 { return nil, nil, ipld.ErrIteratorOverread{} } switch itr.idx { @@ -9819,6 +9862,9 @@ func (itr *_Receipt__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) { case 5: k = &fieldName__Receipt_Logs_serial v = itr.n.Logs.Representation() + case 6: + k = &fieldName__Receipt_LogRootCID_serial + v = itr.n.LogRootCID.Representation() default: panic("unreachable") } @@ -9826,13 +9872,13 @@ func (itr *_Receipt__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) { return } func (itr *_Receipt__ReprMapItr) Done() bool { - return itr.idx >= 6 + return itr.idx >= 7 } func (_Receipt__Repr) ListIterator() ipld.ListIterator { return nil } func (rn *_Receipt__Repr) Length() int64 { - l := 6 + l := 7 return int64(l) } func (_Receipt__Repr) IsAbsent() bool { @@ -9901,6 +9947,7 @@ type _Receipt__ReprAssembler struct { ca_CumulativeGasUsed _Uint__ReprAssembler ca_Bloom _Bloom__ReprAssembler ca_Logs _Logs__ReprAssembler + ca_LogRootCID _Link__ReprAssembler } func (na *_Receipt__ReprAssembler) reset() { @@ -9912,6 +9959,7 @@ func (na *_Receipt__ReprAssembler) reset() { na.ca_CumulativeGasUsed.reset() na.ca_Bloom.reset() na.ca_Logs.reset() + na.ca_LogRootCID.reset() } func (na *_Receipt__ReprAssembler) BeginMap(int64) (ipld.MapAssembler, error) { switch *na.m { @@ -10062,6 +10110,15 @@ func (ma *_Receipt__ReprAssembler) valueFinishTidy() bool { default: return false } + case 6: + switch ma.cm { + case schema.Maybe_Value: + ma.cm = schema.Maybe_Absent + ma.state = maState_initial + return true + default: + return false + } default: panic("unreachable") } @@ -10144,6 +10201,16 @@ func (ma *_Receipt__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssembler, ma.ca_Logs.w = &ma.w.Logs ma.ca_Logs.m = &ma.cm return &ma.ca_Logs, nil + case "LogRootCID": + if ma.s&fieldBit__Receipt_LogRootCID != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__Receipt_LogRootCID_serial} + } + ma.s += fieldBit__Receipt_LogRootCID + ma.state = maState_midValue + ma.f = 6 + ma.ca_LogRootCID.w = &ma.w.LogRootCID + ma.ca_LogRootCID.m = &ma.cm + return &ma.ca_LogRootCID, nil default: } return nil, ipld.ErrInvalidKey{TypeName: "dageth.Receipt.Repr", Key: &_String{k}} @@ -10207,6 +10274,10 @@ func (ma *_Receipt__ReprAssembler) AssembleValue() ipld.NodeAssembler { ma.ca_Logs.w = &ma.w.Logs ma.ca_Logs.m = &ma.cm return &ma.ca_Logs + case 6: + ma.ca_LogRootCID.w = &ma.w.LogRootCID + ma.ca_LogRootCID.m = &ma.cm + return &ma.ca_LogRootCID default: panic("unreachable") } @@ -10240,6 +10311,9 @@ func (ma *_Receipt__ReprAssembler) Finish() error { if ma.s&fieldBit__Receipt_Logs == 0 { err.Missing = append(err.Missing, "Logs") } + if ma.s&fieldBit__Receipt_LogRootCID == 0 { + err.Missing = append(err.Missing, "LogRootCID") + } return err } ma.state = maState_finished @@ -10326,6 +10400,14 @@ func (ka *_Receipt__ReprKeyAssembler) AssignString(k string) error { ka.state = maState_expectValue ka.f = 5 return nil + case "LogRootCID": + if ka.s&fieldBit__Receipt_LogRootCID != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__Receipt_LogRootCID_serial} + } + ka.s += fieldBit__Receipt_LogRootCID + ka.state = maState_expectValue + ka.f = 6 + return nil } return ipld.ErrInvalidKey{TypeName: "dageth.Receipt.Repr", Key: &_String{k}} } @@ -17730,7 +17812,7 @@ func (_TrieBranchNode__ReprKeyAssembler) Prototype() ipld.NodePrototype { func (n _TrieExtensionNode) FieldPartialPath() Bytes { return &n.PartialPath } -func (n _TrieExtensionNode) FieldChild() Child { +func (n _TrieExtensionNode) FieldChild() Link { return &n.Child } @@ -17898,7 +17980,7 @@ type _TrieExtensionNode__Assembler struct { cm schema.Maybe ca_PartialPath _Bytes__Assembler - ca_Child _Child__Assembler + ca_Child _Link__Assembler } func (na *_TrieExtensionNode__Assembler) reset() { @@ -18347,7 +18429,7 @@ type _TrieExtensionNode__ReprAssembler struct { cm schema.Maybe ca_PartialPath _Bytes__ReprAssembler - ca_Child _Child__ReprAssembler + ca_Child _Link__ReprAssembler } func (na *_TrieExtensionNode__ReprAssembler) reset() { @@ -19578,9 +19660,9 @@ func (_TrieLeafNode__ReprKeyAssembler) Prototype() ipld.NodePrototype { func (n _TrieNode) AsInterface() _TrieNode__iface { switch n.tag { case 1: - return n.x1 + return &n.x1 case 2: - return n.x2 + return &n.x2 case 3: return &n.x3 default: @@ -19639,12 +19721,12 @@ func (n TrieNode) LookupByString(key string) (ipld.Node, error) { if n.tag != 1 { return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)} } - return n.x1, nil + return &n.x1, nil case "TrieExtensionNode": if n.tag != 2 { return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)} } - return n.x2, nil + return &n.x2, nil case "TrieLeafNode": if n.tag != 3 { return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)} @@ -19682,9 +19764,9 @@ func (itr *_TrieNode__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) { } switch itr.n.tag { case 1: - k, v = &memberName__TrieNode_TrieBranchNode, itr.n.x1 + k, v = &memberName__TrieNode_TrieBranchNode, &itr.n.x1 case 2: - k, v = &memberName__TrieNode_TrieExtensionNode, itr.n.x2 + k, v = &memberName__TrieNode_TrieExtensionNode, &itr.n.x2 case 3: k, v = &memberName__TrieNode_TrieLeafNode, &itr.n.x3 default: @@ -19909,14 +19991,14 @@ func (ma *_TrieNode__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, err ma.state = maState_midValue ma.ca = 1 ma.w.tag = 1 - ma.ca1.w = ma.w.x1 + ma.ca1.w = &ma.w.x1 ma.ca1.m = &ma.cm return &ma.ca1, nil case "TrieExtensionNode": ma.state = maState_midValue ma.ca = 2 ma.w.tag = 2 - ma.ca2.w = ma.w.x2 + ma.ca2.w = &ma.w.x2 ma.ca2.m = &ma.cm return &ma.ca2, nil case "TrieLeafNode": @@ -19962,21 +20044,15 @@ func (ma *_TrieNode__Assembler) AssembleValue() ipld.NodeAssembler { } ma.state = maState_midValue switch ma.ca { - case 1: - if ma.w.x1 == nil { - ma.w.x1 = &_TrieBranchNode{} - } - ma.ca1.w = ma.w.x1 + case 0: + ma.ca1.w = &ma.w.x1 ma.ca1.m = &ma.cm return &ma.ca1 - case 2: - if ma.w.x2 == nil { - ma.w.x2 = &_TrieExtensionNode{} - } - ma.ca2.w = ma.w.x2 + case 1: + ma.ca2.w = &ma.w.x2 ma.ca2.m = &ma.cm return &ma.ca2 - case 3: + case 2: ma.ca3.w = &ma.w.x3 ma.ca3.m = &ma.cm return &ma.ca3 @@ -20379,14 +20455,14 @@ func (ma *_TrieNode__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssembler, ma.state = maState_midValue ma.ca = 1 ma.w.tag = 1 - ma.ca1.w = ma.w.x1 + ma.ca1.w = &ma.w.x1 ma.ca1.m = &ma.cm return &ma.ca1, nil case "extension": ma.state = maState_midValue ma.ca = 2 ma.w.tag = 2 - ma.ca2.w = ma.w.x2 + ma.ca2.w = &ma.w.x2 ma.ca2.m = &ma.cm return &ma.ca2, nil case "leaf": @@ -20432,21 +20508,15 @@ func (ma *_TrieNode__ReprAssembler) AssembleValue() ipld.NodeAssembler { } ma.state = maState_midValue switch ma.ca { - case 1: - if ma.w.x1 == nil { - ma.w.x1 = &_TrieBranchNode{} - } - ma.ca1.w = ma.w.x1 + case 0: + ma.ca1.w = &ma.w.x1 ma.ca1.m = &ma.cm return &ma.ca1 - case 2: - if ma.w.x2 == nil { - ma.w.x2 = &_TrieExtensionNode{} - } - ma.ca2.w = ma.w.x2 + case 1: + ma.ca2.w = &ma.w.x2 ma.ca2.m = &ma.cm return &ma.ca2 - case 3: + case 2: ma.ca3.w = &ma.w.x3 ma.ca3.m = &ma.cm return &ma.ca3 @@ -21965,19 +22035,19 @@ func (ma *_Value__Assembler) AssembleValue() ipld.NodeAssembler { } ma.state = maState_midValue switch ma.ca { - case 1: + case 0: ma.ca1.w = &ma.w.x1 ma.ca1.m = &ma.cm return &ma.ca1 - case 2: + case 1: ma.ca2.w = &ma.w.x2 ma.ca2.m = &ma.cm return &ma.ca2 - case 3: + case 2: ma.ca3.w = &ma.w.x3 ma.ca3.m = &ma.cm return &ma.ca3 - case 4: + case 3: ma.ca4.w = &ma.w.x4 ma.ca4.m = &ma.cm return &ma.ca4 @@ -22460,19 +22530,19 @@ func (ma *_Value__ReprAssembler) AssembleValue() ipld.NodeAssembler { } ma.state = maState_midValue switch ma.ca { - case 1: + case 0: ma.ca1.w = &ma.w.x1 ma.ca1.m = &ma.cm return &ma.ca1 - case 2: + case 1: ma.ca2.w = &ma.w.x2 ma.ca2.m = &ma.cm return &ma.ca2 - case 3: + case 2: ma.ca3.w = &ma.w.x3 ma.ca3.m = &ma.cm return &ma.ca3 - case 4: + case 3: ma.ca4.w = &ma.w.x4 ma.ca4.m = &ma.cm return &ma.ca4 diff --git a/ipldsch_types.go b/ipldsch_types.go index 67d8643..d9772e6 100644 --- a/ipldsch_types.go +++ b/ipldsch_types.go @@ -205,6 +205,7 @@ type _Receipt struct { CumulativeGasUsed _Uint Bloom _Bloom Logs _Logs + LogRootCID _Link } // Receipts matches the IPLD Schema type "Receipts". It has list kind. @@ -284,7 +285,7 @@ type _TrieBranchNode struct { type TrieExtensionNode = *_TrieExtensionNode type _TrieExtensionNode struct { PartialPath _Bytes - Child _Child + Child _Link } // TrieLeafNode matches the IPLD Schema type "TrieLeafNode". It has Struct type-kind, and may be interrogated like map kind. @@ -299,8 +300,8 @@ type _TrieLeafNode struct { type TrieNode = *_TrieNode type _TrieNode struct { tag uint - x1 *_TrieBranchNode - x2 *_TrieExtensionNode + x1 _TrieBranchNode + x2 _TrieExtensionNode x3 _TrieLeafNode } type _TrieNode__iface interface { From 3f6b39806cabc528cb28f0d2f182362a4db61f82 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 10 Aug 2021 13:41:45 -0500 Subject: [PATCH 10/11] adjustments after new code gen --- log/log_test.go | 10 ++-- log/unmarshal.go | 4 +- log_trie/log_trie_test.go | 25 +++++----- rct/rct_test.go | 11 +++++ rct_trie/rct_trie_test.go | 6 +-- state_trie/state_trie_test.go | 6 +-- storage_trie/storage_trie_test.go | 82 +------------------------------ trie/marshal.go | 4 ++ trie/unmarshal.go | 13 ++--- tx_trie/tx_trie_test.go | 6 +-- 10 files changed, 45 insertions(+), 122 deletions(-) diff --git a/log/log_test.go b/log/log_test.go index c550cfe..e84b7de 100644 --- a/log/log_test.go +++ b/log/log_test.go @@ -10,7 +10,7 @@ import ( "github.com/ipld/go-ipld-prime" dageth "github.com/vulcanize/go-codec-dageth" - "github.com/vulcanize/go-codec-dageth/rct" + "github.com/vulcanize/go-codec-dageth/log" ) var ( @@ -44,8 +44,8 @@ func TestLogCodec(t *testing.T) { func testLogDecoding(t *testing.T) { logBuilder := dageth.Type.Log.NewBuilder() logReader := bytes.NewReader(logEncoding) - if err := rct.Decode(logBuilder, logReader); err != nil { - t.Fatalf("unable to decode legacy Log into an IPLD node: %v", err) + if err := log.Decode(logBuilder, logReader); err != nil { + t.Fatalf("unable to decode log into an IPLD node: %v", err) } logNode = logBuilder.Build() } @@ -63,7 +63,7 @@ func testLogNodeContents(t *testing.T) { t.Errorf("log Address (%x) does not match expected Address (%x)", addrBytes, mockLog.Address.Bytes()) } - dataNode, err := logNode.LookupByString("data") + dataNode, err := logNode.LookupByString("Data") if err != nil { t.Fatalf("log is missing Data: %v", err) } @@ -101,7 +101,7 @@ func testLogNodeContents(t *testing.T) { func testLogEncoding(t *testing.T) { logWriter := new(bytes.Buffer) - if err := rct.Encode(logNode, logWriter); err != nil { + if err := log.Encode(logNode, logWriter); err != nil { t.Fatalf("unable to encode log into writer: %v", err) } logBytes := logWriter.Bytes() diff --git a/log/unmarshal.go b/log/unmarshal.go index bac840c..fec0b5e 100644 --- a/log/unmarshal.go +++ b/log/unmarshal.go @@ -32,11 +32,11 @@ func Decode(na ipld.NodeAssembler, in io.Reader) error { // Decode will grab or read all the bytes from an io.Reader anyway, so this can // save having to copy the bytes or create a bytes.Buffer. func DecodeBytes(na ipld.NodeAssembler, src []byte) error { - var log types.Log + log := new(types.Log) if err := rlp.DecodeBytes(src, log); err != nil { return err } - return DecodeLog(na, log) + return DecodeLog(na, *log) } // DecodeLog unpacks a go-ethereum Log into the NodeAssembler diff --git a/log_trie/log_trie_test.go b/log_trie/log_trie_test.go index a475bff..32df911 100644 --- a/log_trie/log_trie_test.go +++ b/log_trie/log_trie_test.go @@ -16,7 +16,7 @@ import ( "github.com/multiformats/go-multihash" dageth "github.com/vulcanize/go-codec-dageth" - "github.com/vulcanize/go-codec-dageth/rct_trie" + "github.com/vulcanize/go-codec-dageth/log_trie" "github.com/vulcanize/go-codec-dageth/shared" "github.com/vulcanize/go-codec-dageth/trie" ) @@ -36,7 +36,8 @@ var ( mockLeafParitalPath, mockLogVal, } - mockLeafNodeRLP, _ = rlp.EncodeToBytes(mockLeafNode) + mockLeafNodeRLP, _ = rlp.EncodeToBytes(mockLeafNode) + mockExtensionPartialPath = common.Hex2Bytes("1114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45") mockDecodedExtensionPartialPath = shared.CompactToHex(mockExtensionPartialPath) mockExtensionHash = crypto.Keccak256(mockLeafNodeRLP) @@ -140,21 +141,21 @@ func TestLogTrieCodec(t *testing.T) { func testLogTrieDecode(t *testing.T) { branchNodeBuilder := dageth.Type.TrieNode.NewBuilder() branchNodeReader := bytes.NewReader(mockBranchNodeRLP) - if err := rct_trie.Decode(branchNodeBuilder, branchNodeReader); err != nil { + if err := log_trie.Decode(branchNodeBuilder, branchNodeReader); err != nil { t.Fatalf("unable to decode log trie branch node into an IPLD node: %v", err) } branchNode = branchNodeBuilder.Build() extensionNodeBuilder := dageth.Type.TrieNode.NewBuilder() extensionNodeReader := bytes.NewReader(mockExtensionNodeRLP) - if err := rct_trie.Decode(extensionNodeBuilder, extensionNodeReader); err != nil { + if err := log_trie.Decode(extensionNodeBuilder, extensionNodeReader); err != nil { t.Fatalf("unable to decode log trie extension node into an IPLD node: %v", err) } extensionNode = extensionNodeBuilder.Build() leafNodeBuilder := dageth.Type.TrieNode.NewBuilder() leafNodeReader := bytes.NewReader(mockLeafNodeRLP) - if err := rct_trie.Decode(leafNodeBuilder, leafNodeReader); err != nil { + if err := log_trie.Decode(leafNodeBuilder, leafNodeReader); err != nil { t.Fatalf("unable to decode log trie leaf node into an IPLD node: %v", err) } leafNode = leafNodeBuilder.Build() @@ -288,11 +289,7 @@ func verifyExtensionNodeContents(t *testing.T) { if err != nil { t.Fatalf("log trie extension node missing Child: %v", err) } - childLinkNode, err := childNode.LookupByString("Link") - if err != nil { - t.Fatalf("log trie extension node Child should be of kind Link: %v", err) - } - childLink, err := childLinkNode.AsLink() + childLink, err := childNode.AsLink() if err != nil { t.Fatalf("log trie extension node Child should be of kind Link: %v", err) } @@ -354,7 +351,7 @@ func verifyLeafValue(valEnumNode ipld.Node, t *testing.T) { t.Errorf("log Address (%x) does not match expected Address (%x)", addrBytes, mockLog.Address.Bytes()) } - dataNode, err := logNode.LookupByString("data") + dataNode, err := logNode.LookupByString("Data") if err != nil { t.Fatalf("log is missing Data: %v", err) } @@ -392,7 +389,7 @@ func verifyLeafValue(valEnumNode ipld.Node, t *testing.T) { func testLogTrieEncode(t *testing.T) { branchWriter := new(bytes.Buffer) - if err := rct_trie.Encode(branchNode, branchWriter); err != nil { + if err := log_trie.Encode(branchNode, branchWriter); err != nil { t.Fatalf("unable to encode log trie branch node into writer: %v", err) } encodedBranchBytes := branchWriter.Bytes() @@ -401,7 +398,7 @@ func testLogTrieEncode(t *testing.T) { } extensionWriter := new(bytes.Buffer) - if err := rct_trie.Encode(extensionNode, extensionWriter); err != nil { + if err := log_trie.Encode(extensionNode, extensionWriter); err != nil { t.Fatalf("unable to encode log trie extension node into writer: %v", err) } encodedExtensionBytes := extensionWriter.Bytes() @@ -410,7 +407,7 @@ func testLogTrieEncode(t *testing.T) { } leafWriter := new(bytes.Buffer) - if err := rct_trie.Encode(leafNode, leafWriter); err != nil { + if err := log_trie.Encode(leafNode, leafWriter); err != nil { t.Fatalf("unable to encode log trie leaf node into writer: %v", err) } encodedLeafBytes := leafWriter.Bytes() diff --git a/rct/rct_test.go b/rct/rct_test.go index 59abdf6..319d6c5 100644 --- a/rct/rct_test.go +++ b/rct/rct_test.go @@ -106,6 +106,10 @@ func TestReceiptCodec(t *testing.T) { if err != nil { t.Fatalf("unable to marshal access list receipt binary: %v", err) } + dfReceiptConsensusEnc, err = dynamicFeeReceipt.MarshalBinary() + if err != nil { + t.Fatalf("unable to marshal dynamic fee receipt binary: %v", err) + } testReceiptDecoding(t) testAccessListReceiptNodeContents(t) testDynamicFeeReceiptNodeContents(t) @@ -127,6 +131,13 @@ func testReceiptDecoding(t *testing.T) { t.Fatalf("unable to decode access list receipt into an IPLD node: %v", err) } accessListReceiptNode = alRctBuilder.Build() + + dfRctBuilder := dageth.Type.Receipt.NewBuilder() + dfRctReader := bytes.NewReader(dfReceiptConsensusEnc) + if err := rct.Decode(dfRctBuilder, dfRctReader); err != nil { + t.Fatalf("unable to decode dynamic fee receipt into an IPLD node: %v", err) + } + dynamicFeeReceiptNode = dfRctBuilder.Build() } func testAccessListReceiptNodeContents(t *testing.T) { diff --git a/rct_trie/rct_trie_test.go b/rct_trie/rct_trie_test.go index d763be0..351801b 100644 --- a/rct_trie/rct_trie_test.go +++ b/rct_trie/rct_trie_test.go @@ -344,11 +344,7 @@ func verifyExtensionNodeContents(t *testing.T) { if err != nil { t.Fatalf("receipt trie extension node missing Child: %v", err) } - childLinkNode, err := childNode.LookupByString("Link") - if err != nil { - t.Fatalf("receipt trie extension node Child should be of kind Link: %v", err) - } - childLink, err := childLinkNode.AsLink() + childLink, err := childNode.AsLink() if err != nil { t.Fatalf("receipt trie extension node Child should be of kind Link: %v", err) } diff --git a/state_trie/state_trie_test.go b/state_trie/state_trie_test.go index a4cf71e..40f441e 100644 --- a/state_trie/state_trie_test.go +++ b/state_trie/state_trie_test.go @@ -289,11 +289,7 @@ func verifyExtensionNodeContents(t *testing.T) { if err != nil { t.Fatalf("state trie extension node missing Child: %v", err) } - childLinkNode, err := childNode.LookupByString("Link") - if err != nil { - t.Fatalf("state trie extension node Child should be of kind Link: %v", err) - } - childLink, err := childLinkNode.AsLink() + childLink, err := childNode.AsLink() if err != nil { t.Fatalf("state trie extension node Child should be of kind Link: %v", err) } diff --git a/storage_trie/storage_trie_test.go b/storage_trie/storage_trie_test.go index 553d73e..c03d244 100644 --- a/storage_trie/storage_trie_test.go +++ b/storage_trie/storage_trie_test.go @@ -48,12 +48,6 @@ var ( mockLeaf2Val, } - mockExtensionNodeWithLeafIncludedDirectly = []interface{}{ - mockExtensionPartialPath, - mockLeafNode2, - } - mockExtensionNodeWithLeafIncludedDirectlyRLP, _ = rlp.EncodeToBytes(mockExtensionNodeWithLeafIncludedDirectly) - mockChild0 = crypto.Keccak256([]byte{0}) mockChild5 = crypto.Keccak256([]byte{5}) mockChildE = crypto.Keccak256([]byte{14}) @@ -99,7 +93,7 @@ var ( } mockBranchNodeWithLeafIncludedDirectlyRLP, _ = rlp.EncodeToBytes(mockBranchNodeWithLeafIncludedDirectly) - leafNode, extensionNode, extensionNodeWithLeafIncludedDirectly, branchNode, branchNodeWithLeafIncludedDirectly ipld.Node + leafNode, extensionNode, branchNode, branchNodeWithLeafIncludedDirectly ipld.Node ) /* IPLD Schemas @@ -180,13 +174,6 @@ func testStorageTrieDecode(t *testing.T) { } extensionNode = extensionNodeBuilder.Build() - extensionNode2Builder := dageth.Type.TrieNode.NewBuilder() - extensionNode2Reader := bytes.NewReader(mockExtensionNodeWithLeafIncludedDirectlyRLP) - if err := storage_trie.Decode(extensionNode2Builder, extensionNode2Reader); err != nil { - t.Fatalf("unable to decode storage trie extension node into an IPLD node: %v", err) - } - extensionNodeWithLeafIncludedDirectly = extensionNode2Builder.Build() - leafNodeBuilder := dageth.Type.TrieNode.NewBuilder() leafNodeReader := bytes.NewReader(mockLeafNodeRLP) if err := storage_trie.Decode(leafNodeBuilder, leafNodeReader); err != nil { @@ -198,7 +185,6 @@ func testStorageTrieDecode(t *testing.T) { func testStorageTrieNodeContents(t *testing.T) { verifyBranchNodeContents(t) verifyExtensionNodeContents(t) - verifyExtensionNodeWithLeafIncludedDirectlyContents(t) verifyBranchNodeWithLeafIncludedDirectlyContents(t) verifyLeafNodeContents(t) } @@ -486,11 +472,7 @@ func verifyExtensionNodeContents(t *testing.T) { if err != nil { t.Fatalf("storage trie extension node missing Child: %v", err) } - childLinkNode, err := childNode.LookupByString("Link") - if err != nil { - t.Fatalf("storage trie extension node Child should be of kind Link: %v", err) - } - childLink, err := childLinkNode.AsLink() + childLink, err := childNode.AsLink() if err != nil { t.Fatalf("storage trie extension node Child should be of kind Link: %v", err) } @@ -508,66 +490,6 @@ func verifyExtensionNodeContents(t *testing.T) { } } -func verifyExtensionNodeWithLeafIncludedDirectlyContents(t *testing.T) { - ext, err := extensionNodeWithLeafIncludedDirectly.LookupByString(trie.EXTENSION_NODE.String()) - if err != nil { - t.Fatalf("storage trie extension node missing enum key: %v", err) - } - - extPathNode, err := ext.LookupByString("PartialPath") - if err != nil { - t.Fatalf("storage trie extension node missing PartialPath: %v", err) - } - extPathBytes, err := extPathNode.AsBytes() - if err != nil { - t.Fatalf("storage trie extension node PartialPath should be of type Bytes: %v", err) - } - if !bytes.Equal(extPathBytes, mockDecodedExtensionPartialPath) { - t.Errorf("storage trie extension node partial path (%x) does not match expected partial path (%x)", extPathBytes, mockDecodedExtensionPartialPath) - } - - childNode, err := ext.LookupByString("Child") - if err != nil { - t.Fatalf("storage trie extension node missing Child: %v", err) - } - trieNodeNode, err := childNode.LookupByString("TrieNode") - if err != nil { - t.Fatalf("storage trie extension node Child should be of kind TrieNode: %v", err) - } - leaf, err := trieNodeNode.LookupByString(trie.LEAF_NODE.String()) - if err != nil { - t.Fatalf("unable to resolve TrieNode union to a leaf: %v", err) - } - - leafPathNode, err := leaf.LookupByString("PartialPath") - if err != nil { - t.Fatalf("storage trie leaf node missing PartialPath: %v", err) - } - leafPathBytes, err := leafPathNode.AsBytes() - if err != nil { - t.Fatalf("storage trie leaf node PartialPath should be of type Bytes: %v", err) - } - if !bytes.Equal(leafPathBytes, mockDecodedLeaf2PartialPath) { - t.Errorf("storage trie leaf node partial path (%x) does not match expected partial path (%x)", leafPathBytes, mockDecodedLeaf2PartialPath) - } - - leafValEnumNode, err := leaf.LookupByString("Value") - if err != nil { - t.Fatalf("storage trie leaf node missing Value: %v", err) - } - leafValNode, err := leafValEnumNode.LookupByString(trie.STORAGE_VALUE.String()) - if err != nil { - t.Fatalf("unable to resolve Value union to a storage bytes: %v", err) - } - leafValBytes, err := leafValNode.AsBytes() - if err != nil { - t.Fatalf("storage trie leaf node Value should be of type Bytes") - } - if !bytes.Equal(leafValBytes, mockLeaf2Val) { - t.Errorf("storage trie leaf node value (%x) does not match expected value (%x)", leafValBytes, mockLeaf2Val) - } -} - func verifyLeafNodeContents(t *testing.T) { leaf, err := leafNode.LookupByString(trie.LEAF_NODE.String()) if err != nil { diff --git a/trie/marshal.go b/trie/marshal.go index f3cc045..9a48279 100644 --- a/trie/marshal.go +++ b/trie/marshal.go @@ -311,6 +311,10 @@ func ValueAndKind(node ipld.Node) (ipld.Node, ValueKind, error) { if err == nil { return n, STORAGE_VALUE, nil } + n, err = node.LookupByString(LOG_VALUE.String()) + if err == nil { + return n, LOG_VALUE, nil + } return nil, "", fmt.Errorf("eth trie value IPLD node is missing the expected keyed Union keys") } diff --git a/trie/unmarshal.go b/trie/unmarshal.go index 2ac708f..8340feb 100644 --- a/trie/unmarshal.go +++ b/trie/unmarshal.go @@ -7,20 +7,21 @@ import ( "strconv" "strings" - "github.com/vulcanize/go-codec-dageth/log" - - dageth "github.com/vulcanize/go-codec-dageth" - "github.com/vulcanize/go-codec-dageth/shared" - "github.com/ethereum/go-ethereum/rlp" "github.com/ipfs/go-cid" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" + "github.com/vulcanize/go-codec-dageth/log" "github.com/vulcanize/go-codec-dageth/rct" + + dageth "github.com/vulcanize/go-codec-dageth" + "github.com/vulcanize/go-codec-dageth/shared" account "github.com/vulcanize/go-codec-dageth/state_account" "github.com/vulcanize/go-codec-dageth/tx" ) +const logTrieMulticodec = uint64(0x99) // Proposed + // DecodeTrieNode provides an IPLD codec decode interface for eth merkle patricia trie nodes // It's not possible to meet the Decode(na ipld.NodeAssembler, in io.Reader) interface // for a function that supports all trie types (multicodec types), unlike with encoding. @@ -286,7 +287,7 @@ func unpackValue(ma ipld.MapAssembler, val []byte, codec uint64) error { return err } return ma.AssembleValue().AssignBytes(val) - case log.MultiCodecType: + case logTrieMulticodec: if err := ma.AssembleKey().AssignString(LOG_VALUE.String()); err != nil { return err } diff --git a/tx_trie/tx_trie_test.go b/tx_trie/tx_trie_test.go index d373236..19c5675 100644 --- a/tx_trie/tx_trie_test.go +++ b/tx_trie/tx_trie_test.go @@ -356,11 +356,7 @@ func verifyExtensionNodeContents(t *testing.T) { if err != nil { t.Fatalf("transaction trie extension node missing Child: %v", err) } - childLinkNode, err := childNode.LookupByString("Link") - if err != nil { - t.Fatalf("transaction trie extension node Child should be of kind Link: %v", err) - } - childLink, err := childLinkNode.AsLink() + childLink, err := childNode.AsLink() if err != nil { t.Fatalf("transaction trie extension node Child should be of kind Link: %v", err) } From 988aee3250e0e95228b72ce47a57533163019878 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Tue, 10 Aug 2021 13:42:10 -0500 Subject: [PATCH 11/11] adjustments to codegen and manual fixes to Union types --- gen.go | 3 ++ go.mod | 1 + go.sum | 2 + ipldsch_satisfaction.go | 93 +++++++++++++++++++++++++++++++++++------ ipldsch_types.go | 2 + log/unmarshal.go | 3 +- rct/unmarshal.go | 5 +-- 7 files changed, 91 insertions(+), 18 deletions(-) diff --git a/gen.go b/gen.go index 9aa9941..cd2b7e8 100644 --- a/gen.go +++ b/gen.go @@ -255,6 +255,7 @@ func accumulateStateDataStructures(ts *schema.TypeSystem) { | Receipt "rct" | Account "state" | Bytes "storage" + | Log "log" } representation keyed # Child union type used to handle the case where the node is stored directly in the parent node because it is smaller @@ -280,12 +281,14 @@ func accumulateStateDataStructures(ts *schema.TypeSystem) { "Receipt", "Account", "Bytes", + "Log", }, schema.SpawnUnionRepresentationKeyed(map[string]schema.TypeName{ "tx": "Transaction", "rct": "Receipt", "state": "Account", "storage": "Bytes", + "log": "Log", }), )) ts.Accumulate(schema.SpawnUnion("Child", diff --git a/go.mod b/go.mod index 8707352..82e659a 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/ipfs/go-cid v0.0.7 github.com/ipld/go-ipld-prime v0.10.0 github.com/multiformats/go-multihash v0.0.15 + golang.org/dl v0.0.0-20210805175753-70f86bf65abd // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect ) diff --git a/go.sum b/go.sum index 2be95e1..14b7d9b 100644 --- a/go.sum +++ b/go.sum @@ -372,6 +372,8 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/dl v0.0.0-20210805175753-70f86bf65abd h1:zTi7rOU7NMmBInGr/IFQrDXBgYZ2VCO7BlylmxGpQTs= +golang.org/dl v0.0.0-20210805175753-70f86bf65abd/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/ipldsch_satisfaction.go b/ipldsch_satisfaction.go index 534c9d8..357ef85 100644 --- a/ipldsch_satisfaction.go +++ b/ipldsch_satisfaction.go @@ -4031,7 +4031,7 @@ type _Child__Assembler struct { cm schema.Maybe ca1 _Link__Assembler - ca2 _TrieNode__Assembler + ca2 *_TrieNode__Assembler ca uint } @@ -4181,7 +4181,7 @@ func (ma *_Child__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, error) ma.w.tag = 2 ma.ca2.w = &ma.w.x2 ma.ca2.m = &ma.cm - return &ma.ca2, nil + return ma.ca2, nil } return nil, ipld.ErrInvalidKey{TypeName: "dageth.Child", Key: &_String{k}} } @@ -4218,14 +4218,17 @@ func (ma *_Child__Assembler) AssembleValue() ipld.NodeAssembler { } ma.state = maState_midValue switch ma.ca { - case 0: + case 1: ma.ca1.w = &ma.w.x1 ma.ca1.m = &ma.cm return &ma.ca1 - case 1: + case 2: + if ma.ca2 == nil { + ma.ca2 = new(_TrieNode__Assembler) + } ma.ca2.w = &ma.w.x2 ma.ca2.m = &ma.cm - return &ma.ca2 + return ma.ca2 default: panic("unreachable") } @@ -4451,7 +4454,7 @@ type _Child__ReprAssembler struct { w *_Child m *schema.Maybe ca1 _Link__ReprAssembler - ca2 _TrieNode__ReprAssembler + ca2 *_TrieNode__ReprAssembler ca uint } @@ -20044,15 +20047,15 @@ func (ma *_TrieNode__Assembler) AssembleValue() ipld.NodeAssembler { } ma.state = maState_midValue switch ma.ca { - case 0: + case 1: ma.ca1.w = &ma.w.x1 ma.ca1.m = &ma.cm return &ma.ca1 - case 1: + case 2: ma.ca2.w = &ma.w.x2 ma.ca2.m = &ma.cm return &ma.ca2 - case 2: + case 3: ma.ca3.w = &ma.w.x3 ma.ca3.m = &ma.cm return &ma.ca3 @@ -21636,6 +21639,8 @@ func (n _Value) AsInterface() _Value__iface { return &n.x3 case 4: return &n.x4 + case 5: + return &n.x5 default: panic("invalid union state; how did you create this object?") } @@ -21680,6 +21685,7 @@ var ( memberName__Value_Receipt = _String{"Receipt"} memberName__Value_Account = _String{"Account"} memberName__Value_Bytes = _String{"Bytes"} + memberName__Value_Log = _String{"Log"} ) var _ ipld.Node = (Value)(&_Value{}) var _ schema.TypedNode = (Value)(&_Value{}) @@ -21709,6 +21715,11 @@ func (n Value) LookupByString(key string) (ipld.Node, error) { return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)} } return &n.x4, nil + case "Log": + if n.tag != 5 { + return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)} + } + return &n.x5, nil default: return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} } @@ -21748,6 +21759,8 @@ func (itr *_Value__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) { k, v = &memberName__Value_Account, &itr.n.x3 case 4: k, v = &memberName__Value_Bytes, &itr.n.x4 + case 5: + k, v = &memberName__Value_Log, &itr.n.x5 default: panic("unreachable") } @@ -21829,6 +21842,8 @@ type _Value__Assembler struct { ca3 _Account__Assembler ca4 _Bytes__Assembler + + ca5 _Log__Assembler ca uint } @@ -21848,6 +21863,9 @@ func (na *_Value__Assembler) reset() { case 4: na.ca4.reset() + + case 5: + na.ca5.reset() default: panic("unreachable") } @@ -21999,6 +22017,13 @@ func (ma *_Value__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, error) ma.ca4.w = &ma.w.x4 ma.ca4.m = &ma.cm return &ma.ca4, nil + case "Log": + ma.state = maState_midValue + ma.ca = 5 + ma.w.tag = 5 + ma.ca5.w = &ma.w.x5 + ma.ca5.m = &ma.cm + return &ma.ca5, nil } return nil, ipld.ErrInvalidKey{TypeName: "dageth.Value", Key: &_String{k}} } @@ -22035,22 +22060,26 @@ func (ma *_Value__Assembler) AssembleValue() ipld.NodeAssembler { } ma.state = maState_midValue switch ma.ca { - case 0: + case 1: ma.ca1.w = &ma.w.x1 ma.ca1.m = &ma.cm return &ma.ca1 - case 1: + case 2: ma.ca2.w = &ma.w.x2 ma.ca2.m = &ma.cm return &ma.ca2 - case 2: + case 3: ma.ca3.w = &ma.w.x3 ma.ca3.m = &ma.cm return &ma.ca3 - case 3: + case 4: ma.ca4.w = &ma.w.x4 ma.ca4.m = &ma.cm return &ma.ca4 + case 5: + ma.ca5.w = &ma.w.x5 + ma.ca5.m = &ma.cm + return &ma.ca5 default: panic("unreachable") } @@ -22090,6 +22119,8 @@ func (ma *_Value__Assembler) ValuePrototype(k string) ipld.NodePrototype { return _Account__Prototype{} case "Bytes": return _Bytes__Prototype{} + case "Log": + return _Log__Prototype{} default: return nil } @@ -22143,6 +22174,11 @@ func (ka *_Value__KeyAssembler) AssignString(k string) error { ka.w.tag = 4 ka.state = maState_expectValue return nil + case "Log": + ka.ca = 5 + ka.w.tag = 5 + ka.state = maState_expectValue + return nil } return ipld.ErrInvalidKey{TypeName: "dageth.Value", Key: &_String{k}} // TODO: error quality: ErrInvalidUnionDiscriminant ? } @@ -22176,6 +22212,7 @@ var ( memberName__Value_Receipt_serial = _String{"rct"} memberName__Value_Account_serial = _String{"state"} memberName__Value_Bytes_serial = _String{"storage"} + memberName__Value_Log_serial = _String{"log"} ) var _ ipld.Node = &_Value__Repr{} @@ -22204,6 +22241,11 @@ func (n *_Value__Repr) LookupByString(key string) (ipld.Node, error) { return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)} } return n.x4.Representation(), nil + case "log": + if n.tag != 5 { + return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)} + } + return n.x5.Representation(), nil default: return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} } @@ -22243,6 +22285,8 @@ func (itr *_Value__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) { k, v = &memberName__Value_Account_serial, itr.n.x3.Representation() case 4: k, v = &memberName__Value_Bytes_serial, itr.n.x4.Representation() + case 5: + k, v = &memberName__Value_Log_serial, itr.n.x5.Representation() default: panic("unreachable") } @@ -22324,6 +22368,8 @@ type _Value__ReprAssembler struct { ca3 _Account__ReprAssembler ca4 _Bytes__ReprAssembler + + ca5 _Log__ReprAssembler ca uint } @@ -22343,6 +22389,9 @@ func (na *_Value__ReprAssembler) reset() { case 4: na.ca4.reset() + + case 5: + na.ca5.reset() default: panic("unreachable") } @@ -22494,6 +22543,13 @@ func (ma *_Value__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssembler, er ma.ca4.w = &ma.w.x4 ma.ca4.m = &ma.cm return &ma.ca4, nil + case "log": + ma.state = maState_midValue + ma.ca = 5 + ma.w.tag = 5 + ma.ca5.w = &ma.w.x5 + ma.ca5.m = &ma.cm + return &ma.ca5, nil } return nil, ipld.ErrInvalidKey{TypeName: "dageth.Value.Repr", Key: &_String{k}} } @@ -22546,6 +22602,10 @@ func (ma *_Value__ReprAssembler) AssembleValue() ipld.NodeAssembler { ma.ca4.w = &ma.w.x4 ma.ca4.m = &ma.cm return &ma.ca4 + case 4: + ma.ca5.w = &ma.w.x5 + ma.ca5.m = &ma.cm + return &ma.ca5 default: panic("unreachable") } @@ -22585,6 +22645,8 @@ func (ma *_Value__ReprAssembler) ValuePrototype(k string) ipld.NodePrototype { return _Account__ReprPrototype{} case "Bytes": return _Bytes__ReprPrototype{} + case "Log": + return _Log__ReprPrototype{} default: return nil } @@ -22638,6 +22700,11 @@ func (ka *_Value__ReprKeyAssembler) AssignString(k string) error { ka.w.tag = 4 ka.state = maState_expectValue return nil + case "log": + ka.ca = 5 + ka.w.tag = 5 + ka.state = maState_expectValue + return nil } return ipld.ErrInvalidKey{TypeName: "dageth.Value.Repr", Key: &_String{k}} // TODO: error quality: ErrInvalidUnionDiscriminant ? } diff --git a/ipldsch_types.go b/ipldsch_types.go index d9772e6..1ff074c 100644 --- a/ipldsch_types.go +++ b/ipldsch_types.go @@ -335,6 +335,7 @@ type _Value struct { x2 _Receipt x3 _Account x4 _Bytes + x5 _Log } type _Value__iface interface { _Value__member() @@ -344,3 +345,4 @@ func (_Transaction) _Value__member() {} func (_Receipt) _Value__member() {} func (_Account) _Value__member() {} func (_Bytes) _Value__member() {} +func (_Log) _Value__member() {} diff --git a/log/unmarshal.go b/log/unmarshal.go index fec0b5e..7a53a86 100644 --- a/log/unmarshal.go +++ b/log/unmarshal.go @@ -5,9 +5,8 @@ import ( "io" "io/ioutil" - "github.com/ethereum/go-ethereum/rlp" - "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/rlp" "github.com/ipld/go-ipld-prime" ) diff --git a/rct/unmarshal.go b/rct/unmarshal.go index 3346bc7..9cbe656 100644 --- a/rct/unmarshal.go +++ b/rct/unmarshal.go @@ -8,16 +8,15 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/rawdb" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie" "github.com/ipfs/go-cid" + "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" "github.com/multiformats/go-multihash" "github.com/vulcanize/go-codec-dageth/log" - - "github.com/ethereum/go-ethereum/core/types" - "github.com/ipld/go-ipld-prime" ) // Decode provides an IPLD codec decode interface for eth receipt IPLDs.