Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P2P: Clean up protocol interface #180

Closed
wants to merge 90 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
e22e8b7
Environment tests
tgerring Nov 4, 2014
123282e
Update variable name to match unit name
tgerring Nov 4, 2014
e7d9bcd
Added Douglas and Einstein cases
tgerring Nov 4, 2014
b96a59e
Added tests for extra large values
tgerring Nov 4, 2014
92299b7
New test coverage for ethutil/path.go
tgerring Nov 5, 2014
e76c58d
New test coverage for ethutil/big.go
tgerring Nov 5, 2014
94b0ce8
Cleanup big_test.go
tgerring Nov 5, 2014
4f00929
Added byte padding tests
tgerring Nov 5, 2014
cb32f52
added test for parsing bytes
tgerring Nov 5, 2014
92b30cc
add tests for ReadVarInt
tgerring Nov 5, 2014
ada684e
added test for BinaryLength
tgerring Nov 5, 2014
834f8a1
added test for CopyBytes
tgerring Nov 5, 2014
b100546
add test for Bytes.String()
tgerring Nov 5, 2014
4e15ada
Remove fmt dependency
tgerring Nov 5, 2014
ab6b9c4
Added test for IsHex
tgerring Nov 5, 2014
8f94f73
Reorder tests to match source order
tgerring Nov 5, 2014
be96da1
Added tests for FormatData
tgerring Nov 5, 2014
a1d62ab
Restructure StorageSize string test
tgerring Nov 5, 2014
48a3f09
Add coverage for rand
tgerring Nov 5, 2014
0a3a148
Added more byte tests
tgerring Nov 6, 2014
8f3a03c
Update state tests to use gocheck
tgerring Nov 11, 2014
3c619ba
Add verbose comments to TestSnapshot
tgerring Nov 11, 2014
cd94b5f
Convert value_test to use gocheck
tgerring Nov 11, 2014
d9ccbf0
Move test bootstrap to main_test.go
tgerring Nov 11, 2014
bfd1fe9
Update test style to checker
tgerring Nov 11, 2014
c24d143
Convert rand_test to checker
tgerring Nov 11, 2014
cff0d93
Converts bytes_test to checker
tgerring Nov 11, 2014
0d1cdd2
Update TestNumberToBytes
tgerring Nov 11, 2014
12e8404
Fix TestBytestoNumber
tgerring Nov 11, 2014
5c5df21
Update TestDeleteFromByteSlice
tgerring Nov 11, 2014
1d866b5
Merge pull request #1 from tgerring/tests
tgerring Nov 11, 2014
00878e5
Convert trie tests to gocheck
tgerring Nov 12, 2014
6eacc8e
eth-go -> go-ethereum
tgerring Nov 12, 2014
bd9bd4a
Reorg state tests
tgerring Nov 12, 2014
fa59db7
Add initial state/TestDump test
tgerring Nov 12, 2014
461324a
Remove references to mutan
tgerring Nov 12, 2014
313cfba
convert trie encoding tests to checker
tgerring Nov 13, 2014
2a9fc7b
Merge branch 'develop' of https://github.com/tgerring/go-ethereum
tgerring Nov 14, 2014
e6e468e
Merge branch 'develop' of https://github.com/tgerring/go-ethereum int…
tgerring Nov 14, 2014
dcd8cc8
added test file to root directory
tgerring Nov 14, 2014
1ecb3b4
Remove failing Printf
tgerring Nov 14, 2014
dd9e99a
try to get full coverage report on travis
tgerring Nov 15, 2014
9481f86
run coverage after build
tgerring Nov 15, 2014
bc5d924
more travis changes
tgerring Nov 15, 2014
8f9a354
try to fix travis dep error
tgerring Nov 15, 2014
6f7f570
custom travis build script
tgerring Nov 15, 2014
81e7f86
script fix
tgerring Nov 15, 2014
5211fb0
make script executable
tgerring Nov 15, 2014
242667e
update travis build deps
tgerring Nov 16, 2014
1beb9a2
update apt repos
tgerring Nov 16, 2014
0b64906
Add -y flags
tgerring Nov 16, 2014
ec75119
Update deps script
tgerring Nov 16, 2014
3a656c0
add go-nat-pmp to manual install list
tgerring Nov 16, 2014
e1e50f4
add go cover to install list
tgerring Nov 16, 2014
6dbd7a9
add websocket to deps
tgerring Nov 16, 2014
790ded0
Update travis deps script
tgerring Nov 16, 2014
58812fa
Reorg travis.yml
tgerring Nov 16, 2014
71b338e
update travis steps
tgerring Nov 16, 2014
3588c4a
formatting update per gofmt
tgerring Nov 16, 2014
ddca186
update imports order per goimports
tgerring Nov 16, 2014
f82fb88
Add goveralls to travis builds
tgerring Nov 16, 2014
ffab36c
Update ethutil/common tests to checker
tgerring Nov 16, 2014
9095b37
Convert vm test to checker
tgerring Nov 16, 2014
ca74bcc
cleaning up
obscuren Nov 17, 2014
a19d2c2
Merge branch 'develop' into refactor
obscuren Nov 17, 2014
559a81d
enable golint
tgerring Nov 17, 2014
2a5af8f
enable `go vet`
tgerring Nov 17, 2014
5c958ec
Undo running `go vet` in travis
tgerring Nov 17, 2014
f7417d3
New modified patricia trie
obscuren Nov 18, 2014
3220a32
Added some comparison tests for the new ptrie
obscuren Nov 18, 2014
34f29d5
Update vm_debug.go
obscuren Nov 18, 2014
e08aba5
added output test
obscuren Nov 18, 2014
62cd994
j => i
obscuren Nov 18, 2014
a1b6a9a
Begin of moving objects to types package
obscuren Nov 18, 2014
f8d0cd9
Added a callback mechanism to chain adding.
obscuren Nov 18, 2014
675ba4d
Merge branch 'tests' into poc8
obscuren Nov 18, 2014
93e693b
Fixed tests for 'types'
obscuren Nov 18, 2014
437d79f
Updated readme
obscuren Nov 18, 2014
14e2e48
Added `chain` tests & minor fixes
obscuren Nov 19, 2014
e70529a
Added new iterator and tests
obscuren Nov 19, 2014
0f460ad
Added caching and database interface to trie
obscuren Nov 19, 2014
cab7e60
Increased coverage
obscuren Nov 19, 2014
b05e63c
Added paranoia check for tries
obscuren Nov 19, 2014
12f1aea
Fixed iterator for short nodes.
obscuren Nov 20, 2014
9b8a12b
Removed naively casting to bytes
obscuren Nov 20, 2014
8cf9ed0
Fixed test
obscuren Nov 21, 2014
f38052c
p2p: rework protocol API
fjl Nov 4, 2014
7149191
p2p: fix issues found during review
fjl Nov 5, 2014
e4a601c
p2p: disable failing Server tests for now
fjl Nov 10, 2014
59b63ca
p2p: API cleanup and PoC 7 compatibility
fjl Nov 21, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
before_install: sudo apt-get install libgmp3-dev
language: go
go:
- 1.3
before_install:
- sudo add-apt-repository ppa:ubuntu-sdk-team/ppa -y
- sudo apt-get update -qq
- sudo apt-get install -yqq libgmp3-dev qtbase5-private-dev qtdeclarative5-private-dev libqt5opengl5-dev libreadline6-dev
install:
- go get code.google.com/p/go.tools/cmd/goimports
- go get github.com/golang/lint/golint
# - go get code.google.com/p/go.tools/cmd/vet
- go get code.google.com/p/go.tools/cmd/cover
- go get github.com/mattn/goveralls
- ./install_deps.sh
before_script:
- gofmt -l -w .
- goimports -l -w .
- golint .
# - go vet ./...
# - go test -race ./...
script:
- ./gocoverage.sh
after_script:
- goveralls -coverprofile=profile.cov -service=travis-ci -repotoken $COVERALLS_TOKEN
env:
- secure: "U2U1AmkU4NJBgKR/uUAebQY87cNL0+1JHjnLOmmXwxYYyj5ralWb1aSuSH3qSXiT93qLBmtaUkuv9fberHVqrbAeVlztVdUsKAq7JMQH+M99iFkC9UiRMqHmtjWJ0ok4COD1sRYixxi21wb/JrMe3M1iL4QJVS61iltjHhVdM64="

68 changes: 23 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,74 +36,52 @@ Automated (dev) builds
* [Windows] Coming soon™
* [Linux] Coming soon™

Packages
Binaries
========

Ethereum Go is split up in several sub packages Please refer to each
individual package for more information.
1. [eth](https://github.com/ethereum/go-ethereum)
2. [ethchain](https://github.com/ethereum/go-ethereum/tree/master/ethchain)
3. [ethwire](https://github.com/ethereum/go-ethereum/tree/master/ethwire)
4. [ethdb](https://github.com/ethereum/go-ethereum/tree/master/ethdb)
5. [ethutil](https://github.com/ethereum/go-ethereum/tree/master/ethutil)
6. [ethpipe](https://github.com/ethereum/go-ethereum/tree/master/ethpipe)
7. [ethvm](https://github.com/ethereum/go-ethereum/tree/master/ethvm)
8. [ethtrie](https://github.com/ethereum/go-ethereum/tree/master/ethtrie)
9. [ethreact](https://github.com/ethereum/go-ethereum/tree/master/ethreact)
10. [ethlog](https://github.com/ethereum/go-ethereum/tree/master/ethlog)

The [eth](https://github.com/ethereum/go-ethereum) is the top-level package
of the Ethereum protocol. It functions as the Ethereum bootstrapping and
peer communication layer. The [ethchain](https://github.com/ethereum/go-ethereum/tree/master/ethchain)
contains the Ethereum blockchain, block manager, transaction and
transaction handlers. The [ethwire](https://github.com/ethereum/go-ethereum/tree/master/ethwire) contains
the Ethereum [wire protocol](http://wiki.ethereum.org/index.php/Wire_Protocol) which can be used
to hook in to the Ethereum network. [ethutil](https://github.com/ethereum/go-ethereum/tree/master/ethutil) contains
utility functions which are not Ethereum specific. The utility package
contains the [patricia trie](http://wiki.ethereum.org/index.php/Patricia_Tree),
[RLP Encoding](http://wiki.ethereum.org/index.php/RLP) and hex encoding
helpers. The [ethdb](https://github.com/ethereum/go-ethereum/tree/master/ethdb) package
contains the LevelDB interface and memory DB interface.
Go Ethereum comes with several binaries found in
[cmd](https://github.com/ethereum/go-ethereum/tree/master/cmd):

* `mist` Official Ethereum Browser
* `ethereum` Ethereum CLI
* `ethtest` test tool which runs with the [tests](https://github.com/ethereum/testes) suit:
`ethtest "`cat myfile.json`"`.
* `evm` is a generic Ethereum Virtual Machine: `evm -code 60ff60ff -gas
10000 -price 0 -dump`. See `-h` for a detailed description.

General command line options
============================

```
Shared between ethereum and Mist
== Shared between ethereum and Mist ==

= Settings
-id Set the custom identifier of the client (shows up on other clients)
-port Port on which the server will accept incomming connections
-upnp Enable UPnP
-maxpeer Desired amount of peers
-rpc Start JSON RPC

-dir Data directory used to store configs and databases
-import Import a private key
-genaddr Generates a new address and private key (destructive action)
-h This

= Utility
-h This
-import Import a private key
-genaddr Generates a new address and private key (destructive action)
-dump Dump a specific state of a block to stdout given the -number or -hash
-difftool Supress all output and prints VM output to stdout
-diff vm=only vm output, all=all output including state storage

Ethereum only
ethereum [options] [filename]
-js Start the JavaScript REPL
filename Load the given file and interpret as JavaScript
-m Start mining blocks

Mist only
== Mist only ==

-asset_path absolute path to GUI assets directory
```

Tools
=====

Go Ethereum comes with several binaries:

* `mist` Official Ethereum Browser
* `ethereum` Ethereum CLI
* `ethtest` test tool which runs with the [tests](https://github.com/ethereum/testes) suit:
`ethtest "`cat myfile.json`"`.
* `evm` is a generic Ethereum Virtual Machine: `evm -code 60ff60ff -gas
10000 -price 0 -dump`. See `-h` for a detailed description.


Contribution
============

Expand Down
29 changes: 16 additions & 13 deletions block_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
"time"

"github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/chain/types"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/wire"
)

Expand All @@ -20,7 +22,7 @@ var poollogger = logger.NewLogger("BPOOL")
type block struct {
from *Peer
peer *Peer
block *chain.Block
block *types.Block
reqAt time.Time
requested int
}
Expand Down Expand Up @@ -73,7 +75,7 @@ func (self *BlockPool) HasCommonHash(hash []byte) bool {
return self.eth.ChainManager().GetBlock(hash) != nil
}

func (self *BlockPool) Blocks() (blocks chain.Blocks) {
func (self *BlockPool) Blocks() (blocks types.Blocks) {
for _, item := range self.pool {
if item.block != nil {
blocks = append(blocks, item.block)
Expand Down Expand Up @@ -123,15 +125,15 @@ func (self *BlockPool) AddHash(hash []byte, peer *Peer) {
}
}

func (self *BlockPool) Add(b *chain.Block, peer *Peer) {
func (self *BlockPool) Add(b *types.Block, peer *Peer) {
self.addBlock(b, peer, false)
}

func (self *BlockPool) AddNew(b *chain.Block, peer *Peer) {
func (self *BlockPool) AddNew(b *types.Block, peer *Peer) {
self.addBlock(b, peer, true)
}

func (self *BlockPool) addBlock(b *chain.Block, peer *Peer, newBlock bool) {
func (self *BlockPool) addBlock(b *types.Block, peer *Peer, newBlock bool) {
self.mut.Lock()
defer self.mut.Unlock()

Expand Down Expand Up @@ -283,7 +285,7 @@ out:
break out
case <-procTimer.C:
blocks := self.Blocks()
chain.BlockBy(chain.Number).Sort(blocks)
types.BlockBy(types.Number).Sort(blocks)

// Find common block
for i, block := range blocks {
Expand All @@ -309,10 +311,6 @@ out:
}
}

// TODO figure out whether we were catching up
// If caught up and just a new block has been propagated:
// sm.eth.EventMux().Post(NewBlockEvent{block})
// otherwise process and don't emit anything
if len(blocks) > 0 {
chainManager := self.eth.ChainManager()
// Test and import
Expand All @@ -333,9 +331,14 @@ out:
self.td = ethutil.Big0
self.peer = nil
} else {
chainManager.InsertChain(bchain)
for _, block := range blocks {
self.Remove(block.Hash())
if !chain.IsTDError(err) {
chainManager.InsertChain(bchain, func(block *types.Block, messages state.Messages) {
self.eth.EventMux().Post(chain.NewBlockEvent{block})
self.eth.EventMux().Post(messages)

self.Remove(block.Hash())
})

}
}
}
Expand Down
38 changes: 20 additions & 18 deletions chain/block_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sync"
"time"

"github.com/ethereum/go-ethereum/chain/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/event"
Expand Down Expand Up @@ -69,7 +70,7 @@ type BlockManager struct {
// The last attempted block is mainly used for debugging purposes
// This does not have to be a valid block and will be set during
// 'Process' & canonical validation.
lastAttemptedBlock *Block
lastAttemptedBlock *types.Block

events event.Subscription
}
Expand Down Expand Up @@ -117,11 +118,11 @@ func (sm *BlockManager) ChainManager() *ChainManager {
return sm.bc
}

func (self *BlockManager) ProcessTransactions(coinbase *state.StateObject, state *state.State, block, parent *Block, txs Transactions) (Receipts, Transactions, Transactions, Transactions, error) {
func (self *BlockManager) ProcessTransactions(coinbase *state.StateObject, state *state.State, block, parent *types.Block, txs types.Transactions) (types.Receipts, types.Transactions, types.Transactions, types.Transactions, error) {
var (
receipts Receipts
handled, unhandled Transactions
erroneous Transactions
receipts types.Receipts
handled, unhandled types.Transactions
erroneous types.Transactions
totalUsedGas = big.NewInt(0)
err error
)
Expand Down Expand Up @@ -159,8 +160,9 @@ done:

txGas.Sub(txGas, st.gas)
cumulative := new(big.Int).Set(totalUsedGas.Add(totalUsedGas, txGas))
receipt := &Receipt{ethutil.CopyBytes(state.Root()), cumulative, nil /*bloom*/, state.Logs()}
receipt.Bloom = CreateBloom(Receipts{receipt})
receipt := types.NewReceipt(state.Root(), cumulative)
receipt.SetLogs(state.Logs())
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})

// Notify all subscribers
go self.eth.EventMux().Post(TxPostEvent{tx})
Expand All @@ -178,7 +180,7 @@ done:
return receipts, handled, unhandled, erroneous, err
}

func (sm *BlockManager) Process(block *Block) (td *big.Int, msgs state.Messages, err error) {
func (sm *BlockManager) Process(block *types.Block) (td *big.Int, msgs state.Messages, err error) {
// Processing a blocks may never happen simultaneously
sm.mutex.Lock()
defer sm.mutex.Unlock()
Expand All @@ -195,7 +197,7 @@ func (sm *BlockManager) Process(block *Block) (td *big.Int, msgs state.Messages,
return sm.ProcessWithParent(block, parent)
}

func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, messages state.Messages, err error) {
func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.Int, messages state.Messages, err error) {
sm.lastAttemptedBlock = block

state := parent.State().Copy()
Expand All @@ -215,13 +217,13 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
return
}

txSha := DeriveSha(block.transactions)
txSha := types.DeriveSha(block.Transactions())
if bytes.Compare(txSha, block.TxSha) != 0 {
err = fmt.Errorf("validating transaction root. received=%x got=%x", block.TxSha, txSha)
return
}

receiptSha := DeriveSha(receipts)
receiptSha := types.DeriveSha(receipts)
if bytes.Compare(receiptSha, block.ReceiptSha) != 0 {
err = fmt.Errorf("validating receipt root. received=%x got=%x", block.ReceiptSha, receiptSha)
return
Expand All @@ -238,8 +240,8 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
return
}

block.receipts = receipts // although this isn't necessary it be in the future
rbloom := CreateBloom(receipts)
//block.receipts = receipts // although this isn't necessary it be in the future
rbloom := types.CreateBloom(receipts)
if bytes.Compare(rbloom, block.LogsBloom) != 0 {
err = fmt.Errorf("unable to replicate block's bloom=%x", rbloom)
return
Expand Down Expand Up @@ -272,7 +274,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
}
}

func (sm *BlockManager) ApplyDiff(state *state.State, parent, block *Block) (receipts Receipts, err error) {
func (sm *BlockManager) ApplyDiff(state *state.State, parent, block *types.Block) (receipts types.Receipts, err error) {
coinbase := state.GetOrNewStateObject(block.Coinbase)
coinbase.SetGasPool(block.CalcGasLimit(parent))

Expand All @@ -285,7 +287,7 @@ func (sm *BlockManager) ApplyDiff(state *state.State, parent, block *Block) (rec
return receipts, nil
}

func (sm *BlockManager) CalculateTD(block *Block) (*big.Int, bool) {
func (sm *BlockManager) CalculateTD(block *types.Block) (*big.Int, bool) {
uncleDiff := new(big.Int)
for _, uncle := range block.Uncles {
uncleDiff = uncleDiff.Add(uncleDiff, uncle.Difficulty)
Expand All @@ -311,7 +313,7 @@ func (sm *BlockManager) CalculateTD(block *Block) (*big.Int, bool) {
// Validates the current block. Returns an error if the block was invalid,
// an uncle or anything that isn't on the current block chain.
// Validation validates easy over difficult (dagger takes longer time = difficult)
func (sm *BlockManager) ValidateBlock(block, parent *Block) error {
func (sm *BlockManager) ValidateBlock(block, parent *types.Block) error {
expd := CalcDifficulty(block, parent)
if expd.Cmp(block.Difficulty) < 0 {
return fmt.Errorf("Difficulty check failed for block %v, %v", block.Difficulty, expd)
Expand All @@ -337,7 +339,7 @@ func (sm *BlockManager) ValidateBlock(block, parent *Block) error {
return nil
}

func (sm *BlockManager) AccumelateRewards(state *state.State, block, parent *Block) error {
func (sm *BlockManager) AccumelateRewards(state *state.State, block, parent *types.Block) error {
reward := new(big.Int).Set(BlockReward)

knownUncles := ethutil.Set(parent.Uncles)
Expand Down Expand Up @@ -380,7 +382,7 @@ func (sm *BlockManager) AccumelateRewards(state *state.State, block, parent *Blo
return nil
}

func (sm *BlockManager) GetMessages(block *Block) (messages []*state.Message, err error) {
func (sm *BlockManager) GetMessages(block *types.Block) (messages []*state.Message, err error) {
if !sm.bc.HasBlock(block.PrevHash) {
return nil, ParentError(block.PrevHash)
}
Expand Down
Loading