Skip to content

Commit ef7961b

Browse files
committed
Merge pull request bnb-chain#194 from ethereum/poc8
Update tests branch to PoC8
2 parents c17a3cb + 8cf9ed0 commit ef7961b

61 files changed

Lines changed: 5369 additions & 1120 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -36,74 +36,52 @@ Automated (dev) builds
3636
* [Windows] Coming soon™
3737
* [Linux] Coming soon™
3838

39-
Packages
39+
Binaries
4040
========
4141

42-
Ethereum Go is split up in several sub packages Please refer to each
43-
individual package for more information.
44-
1. [eth](https://github.com/ethereum/go-ethereum)
45-
2. [ethchain](https://github.com/ethereum/go-ethereum/tree/master/ethchain)
46-
3. [ethwire](https://github.com/ethereum/go-ethereum/tree/master/ethwire)
47-
4. [ethdb](https://github.com/ethereum/go-ethereum/tree/master/ethdb)
48-
5. [ethutil](https://github.com/ethereum/go-ethereum/tree/master/ethutil)
49-
6. [ethpipe](https://github.com/ethereum/go-ethereum/tree/master/ethpipe)
50-
7. [ethvm](https://github.com/ethereum/go-ethereum/tree/master/ethvm)
51-
8. [ethtrie](https://github.com/ethereum/go-ethereum/tree/master/ethtrie)
52-
9. [ethreact](https://github.com/ethereum/go-ethereum/tree/master/ethreact)
53-
10. [ethlog](https://github.com/ethereum/go-ethereum/tree/master/ethlog)
54-
55-
The [eth](https://github.com/ethereum/go-ethereum) is the top-level package
56-
of the Ethereum protocol. It functions as the Ethereum bootstrapping and
57-
peer communication layer. The [ethchain](https://github.com/ethereum/go-ethereum/tree/master/ethchain)
58-
contains the Ethereum blockchain, block manager, transaction and
59-
transaction handlers. The [ethwire](https://github.com/ethereum/go-ethereum/tree/master/ethwire) contains
60-
the Ethereum [wire protocol](http://wiki.ethereum.org/index.php/Wire_Protocol) which can be used
61-
to hook in to the Ethereum network. [ethutil](https://github.com/ethereum/go-ethereum/tree/master/ethutil) contains
62-
utility functions which are not Ethereum specific. The utility package
63-
contains the [patricia trie](http://wiki.ethereum.org/index.php/Patricia_Tree),
64-
[RLP Encoding](http://wiki.ethereum.org/index.php/RLP) and hex encoding
65-
helpers. The [ethdb](https://github.com/ethereum/go-ethereum/tree/master/ethdb) package
66-
contains the LevelDB interface and memory DB interface.
42+
Go Ethereum comes with several binaries found in
43+
[cmd](https://github.com/ethereum/go-ethereum/tree/master/cmd):
44+
45+
* `mist` Official Ethereum Browser
46+
* `ethereum` Ethereum CLI
47+
* `ethtest` test tool which runs with the [tests](https://github.com/ethereum/testes) suit:
48+
`ethtest "`cat myfile.json`"`.
49+
* `evm` is a generic Ethereum Virtual Machine: `evm -code 60ff60ff -gas
50+
10000 -price 0 -dump`. See `-h` for a detailed description.
6751

6852
General command line options
6953
============================
7054

7155
```
72-
Shared between ethereum and Mist
56+
== Shared between ethereum and Mist ==
57+
58+
= Settings
7359
-id Set the custom identifier of the client (shows up on other clients)
7460
-port Port on which the server will accept incomming connections
7561
-upnp Enable UPnP
7662
-maxpeer Desired amount of peers
7763
-rpc Start JSON RPC
78-
7964
-dir Data directory used to store configs and databases
80-
-import Import a private key
81-
-genaddr Generates a new address and private key (destructive action)
82-
-h This
65+
66+
= Utility
67+
-h This
68+
-import Import a private key
69+
-genaddr Generates a new address and private key (destructive action)
70+
-dump Dump a specific state of a block to stdout given the -number or -hash
71+
-difftool Supress all output and prints VM output to stdout
72+
-diff vm=only vm output, all=all output including state storage
8373
8474
Ethereum only
8575
ethereum [options] [filename]
8676
-js Start the JavaScript REPL
8777
filename Load the given file and interpret as JavaScript
8878
-m Start mining blocks
8979
90-
Mist only
80+
== Mist only ==
81+
9182
-asset_path absolute path to GUI assets directory
9283
```
9384

94-
Tools
95-
=====
96-
97-
Go Ethereum comes with several binaries:
98-
99-
* `mist` Official Ethereum Browser
100-
* `ethereum` Ethereum CLI
101-
* `ethtest` test tool which runs with the [tests](https://github.com/ethereum/testes) suit:
102-
`ethtest "`cat myfile.json`"`.
103-
* `evm` is a generic Ethereum Virtual Machine: `evm -code 60ff60ff -gas
104-
10000 -price 0 -dump`. See `-h` for a detailed description.
105-
106-
10785
Contribution
10886
============
10987

‎block_pool.go‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import (
1010
"time"
1111

1212
"github.com/ethereum/go-ethereum/chain"
13+
"github.com/ethereum/go-ethereum/chain/types"
1314
"github.com/ethereum/go-ethereum/ethutil"
1415
"github.com/ethereum/go-ethereum/logger"
16+
"github.com/ethereum/go-ethereum/state"
1517
"github.com/ethereum/go-ethereum/wire"
1618
)
1719

@@ -20,7 +22,7 @@ var poollogger = logger.NewLogger("BPOOL")
2022
type block struct {
2123
from *Peer
2224
peer *Peer
23-
block *chain.Block
25+
block *types.Block
2426
reqAt time.Time
2527
requested int
2628
}
@@ -73,7 +75,7 @@ func (self *BlockPool) HasCommonHash(hash []byte) bool {
7375
return self.eth.ChainManager().GetBlock(hash) != nil
7476
}
7577

76-
func (self *BlockPool) Blocks() (blocks chain.Blocks) {
78+
func (self *BlockPool) Blocks() (blocks types.Blocks) {
7779
for _, item := range self.pool {
7880
if item.block != nil {
7981
blocks = append(blocks, item.block)
@@ -123,15 +125,15 @@ func (self *BlockPool) AddHash(hash []byte, peer *Peer) {
123125
}
124126
}
125127

126-
func (self *BlockPool) Add(b *chain.Block, peer *Peer) {
128+
func (self *BlockPool) Add(b *types.Block, peer *Peer) {
127129
self.addBlock(b, peer, false)
128130
}
129131

130-
func (self *BlockPool) AddNew(b *chain.Block, peer *Peer) {
132+
func (self *BlockPool) AddNew(b *types.Block, peer *Peer) {
131133
self.addBlock(b, peer, true)
132134
}
133135

134-
func (self *BlockPool) addBlock(b *chain.Block, peer *Peer, newBlock bool) {
136+
func (self *BlockPool) addBlock(b *types.Block, peer *Peer, newBlock bool) {
135137
self.mut.Lock()
136138
defer self.mut.Unlock()
137139

@@ -283,7 +285,7 @@ out:
283285
break out
284286
case <-procTimer.C:
285287
blocks := self.Blocks()
286-
chain.BlockBy(chain.Number).Sort(blocks)
288+
types.BlockBy(types.Number).Sort(blocks)
287289

288290
// Find common block
289291
for i, block := range blocks {
@@ -309,10 +311,6 @@ out:
309311
}
310312
}
311313

312-
// TODO figure out whether we were catching up
313-
// If caught up and just a new block has been propagated:
314-
// sm.eth.EventMux().Post(NewBlockEvent{block})
315-
// otherwise process and don't emit anything
316314
if len(blocks) > 0 {
317315
chainManager := self.eth.ChainManager()
318316
// Test and import
@@ -333,9 +331,14 @@ out:
333331
self.td = ethutil.Big0
334332
self.peer = nil
335333
} else {
336-
chainManager.InsertChain(bchain)
337-
for _, block := range blocks {
338-
self.Remove(block.Hash())
334+
if !chain.IsTDError(err) {
335+
chainManager.InsertChain(bchain, func(block *types.Block, messages state.Messages) {
336+
self.eth.EventMux().Post(chain.NewBlockEvent{block})
337+
self.eth.EventMux().Post(messages)
338+
339+
self.Remove(block.Hash())
340+
})
341+
339342
}
340343
}
341344
}

‎chain/block_manager.go‎

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"sync"
1010
"time"
1111

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

7475
events event.Subscription
7576
}
@@ -117,11 +118,11 @@ func (sm *BlockManager) ChainManager() *ChainManager {
117118
return sm.bc
118119
}
119120

120-
func (self *BlockManager) ProcessTransactions(coinbase *state.StateObject, state *state.State, block, parent *Block, txs Transactions) (Receipts, Transactions, Transactions, Transactions, error) {
121+
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) {
121122
var (
122-
receipts Receipts
123-
handled, unhandled Transactions
124-
erroneous Transactions
123+
receipts types.Receipts
124+
handled, unhandled types.Transactions
125+
erroneous types.Transactions
125126
totalUsedGas = big.NewInt(0)
126127
err error
127128
)
@@ -159,8 +160,9 @@ done:
159160

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

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

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

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

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

218-
txSha := DeriveSha(block.transactions)
220+
txSha := types.DeriveSha(block.Transactions())
219221
if bytes.Compare(txSha, block.TxSha) != 0 {
220222
err = fmt.Errorf("validating transaction root. received=%x got=%x", block.TxSha, txSha)
221223
return
222224
}
223225

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

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

275-
func (sm *BlockManager) ApplyDiff(state *state.State, parent, block *Block) (receipts Receipts, err error) {
277+
func (sm *BlockManager) ApplyDiff(state *state.State, parent, block *types.Block) (receipts types.Receipts, err error) {
276278
coinbase := state.GetOrNewStateObject(block.Coinbase)
277279
coinbase.SetGasPool(block.CalcGasLimit(parent))
278280

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

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

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

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

383-
func (sm *BlockManager) GetMessages(block *Block) (messages []*state.Message, err error) {
385+
func (sm *BlockManager) GetMessages(block *types.Block) (messages []*state.Message, err error) {
384386
if !sm.bc.HasBlock(block.PrevHash) {
385387
return nil, ParentError(block.PrevHash)
386388
}

0 commit comments

Comments
 (0)