Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

First implementation of vetting tools. #2

Merged
merged 13 commits into from Jul 21, 2017
Merged

First implementation of vetting tools. #2

merged 13 commits into from Jul 21, 2017

Conversation

ghost
Copy link

@ghost ghost commented Jul 20, 2017

  • First Implementation of vetting tools:
    • unused
    • gosimple
    • staticcheck
    • golint
  • Added TODO notes
  • Added documentation and hacks to be able to run this plugin on scenarios different from linux.
    • Noted techniques are non invasive to the plugin layout.
  • Next Steps (to be copied in this issue)
    • Refactor to comply with eth-block to be a block header refactor/block-header.
    • Add support for state trie element retrieval feat/state-trie.
    • Extend this program to a repo to be called go-ipld-eth-dump-star, which will be a CLI app where you provide a block hash, and this program will recursively retrieve and add to IPFS block header, ommer list, state trie elements, etc; Until complete the 8 IPLD types. This should be the angular stone to the ambitious project of having the whole eth blockchain on IPFS.
      • To accomplish above, we will need to build a patch to go-ethereum's ethapi package, to retrieve whatever we need.
      • Support for the rest of the 8 IPLD types.
[0x90] eth-block 
  ommers: eth-block-list
  txs: eth-tx-trie
  receipts: eth-tx-receipt-trie
  state: eth-state-trie

[0x91] eth-tx (local data only)
[0x92] eth-tx-receipt (local data only)
[0x93] eth-account-snapshot (local data only)

[0x94] eth-block-list (rlp array)
  [leaves]: eth-block

[0x95] eth-tx-trie (merkle trie)
  [leaves]: eth-tx

[0x96] eth-tx-receipt-trie (merkle trie)
  [leaves]: links to eth-tx-receipt

[0x97] eth-state-trie (secure merkle trie)
  [leaves]: links to eth-account-snapshot

[0x98] eth-storage-trie (secure merkle trie)
  [leaves]: links to raw binary

@ghost ghost mentioned this pull request Jul 20, 2017
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the documentation looks fine (although I haven't thoroughly read the markdown documentation files).

Most of my comments are just addressing questions in the code.

block.go Outdated
cid "github.com/ipfs/go-cid"
node "github.com/ipfs/go-ipld-format"
mh "github.com/multiformats/go-multihash"
cid "gx/ipfs/QmTprEaAA2A9bst5XH7exuyi5KzNMK3SEDNN8rBDnKWcUS/go-cid"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally don't leave imports in gx form in any repo but go-ipfs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. TIL: gx-go hook pre-test and gx-go hook post-test.

block.go Outdated
// Copy is NOT IMPLEMENTED YET
// Should return a deep copy of this node.
// TODO
// TBD how deep we want to copy this node.
func (b *EthBlock) Copy() node.Node {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sigh... The simplest way to do this is to just encode then decode. That gives you a guaranteed copy 😁. I don't think anything will call this so performance shouldn't be that much of an issue.

However, this method really has no place here because IPLD nodes should be immutable once constructed. It's a remanent from the past at this point. Unfortunately, we still have to update the interface (take a look at the issues) and doing that will require quite a bit of cross-project refactoring.

block.go Outdated
@@ -162,6 +164,7 @@ func (b *EthBlock) MarshalJSON() ([]byte, error) {
return json.Marshal(out)
}

// Cid returns the content identifier of the block header.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually just abbreviate "content identifier" as CID (kind of like how nobody calls http "hyper-text transport protocol").

block.go Outdated
@@ -175,18 +178,25 @@ func (b *EthBlock) Cid() *cid.Cid {
return c
}

// Parent returns the content identifier of the parent of the block.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

content identifier -> CID

block.go Outdated
func (b *EthBlock) Parent() *cid.Cid {
return toCid(MEthBlock, b.header.ParentHash.Bytes())
}

// Tx returns the content identifier of the transactionsTrie root of the block.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

content identifier -> CID

block.go Outdated
@@ -249,19 +265,27 @@ func (b *EthBlock) ResolveLink(p []string) (*node.Link, []string, error) {
return nil, nil, fmt.Errorf("resolved item was not a link")
}

// Size returns the size in bytes of the serialized object
func (b *EthBlock) Size() (uint64, error) {
// TODO:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case you're wondering what this should return... the answer is it doesn't matter. This function will go away as a part of the great go-ipld-format refactor (every IPLD format handles size differently so it's kind of useless at the moment).

block.go Outdated
func (b *EthBlock) Size() (uint64, error) {
// TODO:
return 0, nil
}

// Stat helps this struct to comply with the Node interface
// TODO: not sure if stat deserves to stay
func (b *EthBlock) Stat() (*node.NodeStat, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has to stay (:sob:) for now but yeah, this will also go away.

trie.go Outdated
@@ -76,34 +77,39 @@ func NewTrieNode(data []byte) (node.Node, error) {
}
}

func (b *TrieNode) Cid() *cid.Cid {
// Cid returns the content identifier of the trie
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

content identifier -> CID.

trie.go Outdated
if err != nil {
panic(err)
}
return c
}

// HexHash returns the hex hash of the trie
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "hex hash" the standard name for this in etherland?

tx.go Outdated
type Tx struct {
tx *types.Transaction
}

func (b *Tx) Cid() *cid.Cid {
// Cid returns the content identifier of the transaction.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

content identifier -> CID

@ghost
Copy link
Author

ghost commented Jul 21, 2017

@Stebalien All observations solved. Moving on to the eth-block branch.

block_test.go Outdated
fmt.Println(c)

_ = c
// f_ = cmt.Println(c)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably be either using this value or not generating it. What's this test for?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's legacy code. I planned to improve the test on a later PR. Will delete it now.

block_test.go Outdated
@@ -63,5 +64,6 @@ func TestBlockWithOddTransactions(t *testing.T) {
t.Fatal(err)
}

fmt.Printf("%x\n", blk.Tx().Bytes())
_ = blk
// fmt.Printf("%x\n", blk.Tx().Bytes())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. It is legacy code. I'm properly dealing with the tests for block in the next PR.

@ghost
Copy link
Author

ghost commented Jul 21, 2017

@Stebalien should we be good to merge this one?

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Stebalien
Copy link
Member

Ah, except I can't merge on this repo... let me ping @whyrusleeping.

@whyrusleeping whyrusleeping merged commit d33d669 into ipfs:master Jul 21, 2017
@ghost ghost deleted the feat/vetting branch July 31, 2017 11:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants