Skip to content

Commit 6abf8ef

Browse files
committed
Merge
1 parent b0854fb commit 6abf8ef

41 files changed

Lines changed: 2303 additions & 1177 deletions

Some content is hidden

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

‎cmd/ethereum/flags.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ var (
5959
DumpNumber int
6060
VmType int
6161
ImportChain string
62+
SHH bool
63+
Dial bool
6264
)
6365

6466
// flags specific to cli client
@@ -94,6 +96,8 @@ func Init() {
9496
flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server")
9597
flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
9698
flag.BoolVar(&UseSeed, "seed", true, "seed peers")
99+
flag.BoolVar(&SHH, "shh", true, "whisper protocol (on)")
100+
flag.BoolVar(&Dial, "dial", true, "dial out connections (on)")
97101
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
98102
flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
99103
flag.StringVar(&ExportDir, "export", "", "exports the session keyring to files in the directory given")
@@ -105,7 +109,7 @@ func Init() {
105109
flag.BoolVar(&DiffTool, "difftool", false, "creates output for diff'ing. Sets LogLevel=0")
106110
flag.StringVar(&DiffType, "diff", "all", "sets the level of diff output [vm, all]. Has no effect if difftool=false")
107111
flag.BoolVar(&ShowGenesis, "genesis", false, "Dump the genesis block")
108-
flag.StringVar(&ImportChain, "chain", "", "Imports fiven chain")
112+
flag.StringVar(&ImportChain, "chain", "", "Imports given chain")
109113

110114
flag.BoolVar(&Dump, "dump", false, "output the ethereum state in JSON format. Sub args [number, hash]")
111115
flag.StringVar(&DumpHash, "hash", "", "specify arg in hex")

‎cmd/ethereum/main.go‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@ func main() {
6464
NATType: PMPGateway,
6565
PMPGateway: PMPGateway,
6666
KeyRing: KeyRing,
67+
Shh: SHH,
68+
Dial: Dial,
6769
})
70+
6871
if err != nil {
6972
clilogger.Fatalln(err)
7073
}
74+
7175
utils.KeyTasks(ethereum.KeyManager(), KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
7276

7377
if Dump {
@@ -112,13 +116,6 @@ func main() {
112116
return
113117
}
114118

115-
// better reworked as cases
116-
if StartJsConsole {
117-
InitJsConsole(ethereum)
118-
} else if len(InputFile) > 0 {
119-
ExecJsFile(ethereum, InputFile)
120-
}
121-
122119
if StartRpc {
123120
utils.StartRpc(ethereum, RpcPort)
124121
}
@@ -129,6 +126,11 @@ func main() {
129126

130127
utils.StartEthereum(ethereum, UseSeed)
131128

129+
if StartJsConsole {
130+
InitJsConsole(ethereum)
131+
} else if len(InputFile) > 0 {
132+
ExecJsFile(ethereum, InputFile)
133+
}
132134
// this blocks the thread
133135
ethereum.WaitForShutdown()
134136
}

‎core/transaction_pool.go‎

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/ethereum/go-ethereum/ethutil"
88
"github.com/ethereum/go-ethereum/event"
99
"github.com/ethereum/go-ethereum/logger"
10-
"gopkg.in/fatih/set.v0"
1110
)
1211

1312
var txplogger = logger.NewLogger("TXP")
@@ -38,7 +37,7 @@ type TxPool struct {
3837
quit chan bool
3938
// The actual pool
4039
//pool *list.List
41-
pool *set.Set
40+
txs map[string]*types.Transaction
4241

4342
SecondaryProcessor TxProcessor
4443

@@ -49,21 +48,19 @@ type TxPool struct {
4948

5049
func NewTxPool(eventMux *event.TypeMux) *TxPool {
5150
return &TxPool{
52-
pool: set.New(),
51+
txs: make(map[string]*types.Transaction),
5352
queueChan: make(chan *types.Transaction, txPoolQueueSize),
5453
quit: make(chan bool),
5554
eventMux: eventMux,
5655
}
5756
}
5857

59-
func (pool *TxPool) addTransaction(tx *types.Transaction) {
60-
pool.pool.Add(tx)
61-
62-
// Broadcast the transaction to the rest of the peers
63-
pool.eventMux.Post(TxPreEvent{tx})
64-
}
65-
6658
func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
59+
hash := tx.Hash()
60+
if pool.txs[string(hash)] != nil {
61+
return fmt.Errorf("Known transaction (%x)", hash[0:4])
62+
}
63+
6764
if len(tx.To()) != 0 && len(tx.To()) != 20 {
6865
return fmt.Errorf("Invalid recipient. len = %d", len(tx.To()))
6966
}
@@ -95,18 +92,17 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
9592
return nil
9693
}
9794

98-
func (self *TxPool) Add(tx *types.Transaction) error {
99-
hash := tx.Hash()
100-
if self.pool.Has(tx) {
101-
return fmt.Errorf("Known transaction (%x)", hash[0:4])
102-
}
95+
func (self *TxPool) addTx(tx *types.Transaction) {
96+
self.txs[string(tx.Hash())] = tx
97+
}
10398

99+
func (self *TxPool) Add(tx *types.Transaction) error {
104100
err := self.ValidateTransaction(tx)
105101
if err != nil {
106102
return err
107103
}
108104

109-
self.addTransaction(tx)
105+
self.addTx(tx)
110106

111107
var to string
112108
if len(tx.To()) > 0 {
@@ -124,7 +120,7 @@ func (self *TxPool) Add(tx *types.Transaction) error {
124120
}
125121

126122
func (self *TxPool) Size() int {
127-
return self.pool.Size()
123+
return len(self.txs)
128124
}
129125

130126
func (self *TxPool) AddTransactions(txs []*types.Transaction) {
@@ -137,43 +133,39 @@ func (self *TxPool) AddTransactions(txs []*types.Transaction) {
137133
}
138134
}
139135

140-
func (pool *TxPool) GetTransactions() []*types.Transaction {
141-
txList := make([]*types.Transaction, pool.Size())
136+
func (self *TxPool) GetTransactions() (txs types.Transactions) {
137+
txs = make(types.Transactions, self.Size())
142138
i := 0
143-
pool.pool.Each(func(v interface{}) bool {
144-
txList[i] = v.(*types.Transaction)
139+
for _, tx := range self.txs {
140+
txs[i] = tx
145141
i++
142+
}
146143

147-
return true
148-
})
149-
150-
return txList
144+
return
151145
}
152146

153147
func (pool *TxPool) RemoveInvalid(query StateQuery) {
154148
var removedTxs types.Transactions
155-
pool.pool.Each(func(v interface{}) bool {
156-
tx := v.(*types.Transaction)
149+
for _, tx := range pool.txs {
157150
sender := query.GetAccount(tx.From())
158151
err := pool.ValidateTransaction(tx)
159152
if err != nil || sender.Nonce >= tx.Nonce() {
160153
removedTxs = append(removedTxs, tx)
161154
}
155+
}
162156

163-
return true
164-
})
165157
pool.RemoveSet(removedTxs)
166158
}
167159

168160
func (self *TxPool) RemoveSet(txs types.Transactions) {
169161
for _, tx := range txs {
170-
self.pool.Remove(tx)
162+
delete(self.txs, string(tx.Hash()))
171163
}
172164
}
173165

174166
func (pool *TxPool) Flush() []*types.Transaction {
175167
txList := pool.GetTransactions()
176-
pool.pool.Clear()
168+
pool.txs = make(map[string]*types.Transaction)
177169

178170
return txList
179171
}

‎core/types/block.go‎

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@ func (self *Header) HashNoNonce() []byte {
6767
}
6868

6969
type Block struct {
70-
header *Header
71-
uncles []*Header
72-
transactions Transactions
73-
Td *big.Int
70+
// Preset Hash for mock
71+
HeaderHash []byte
72+
ParentHeaderHash []byte
73+
header *Header
74+
uncles []*Header
75+
transactions Transactions
76+
Td *big.Int
7477

7578
receipts Receipts
7679
Reward *big.Int
@@ -99,41 +102,19 @@ func NewBlockWithHeader(header *Header) *Block {
99102
}
100103

101104
func (self *Block) DecodeRLP(s *rlp.Stream) error {
102-
if _, err := s.List(); err != nil {
103-
return err
104-
}
105-
106-
var header Header
107-
if err := s.Decode(&header); err != nil {
108-
return err
109-
}
110-
111-
var transactions []*Transaction
112-
if err := s.Decode(&transactions); err != nil {
113-
return err
105+
var extblock struct {
106+
Header *Header
107+
Txs []*Transaction
108+
Uncles []*Header
109+
TD *big.Int // optional
114110
}
115-
116-
var uncleHeaders []*Header
117-
if err := s.Decode(&uncleHeaders); err != nil {
118-
return err
119-
}
120-
121-
var tdBytes []byte
122-
if err := s.Decode(&tdBytes); err != nil {
123-
// If this block comes from the network that's fine. If loaded from disk it should be there
124-
// Blocks don't store their Td when propagated over the network
125-
} else {
126-
self.Td = ethutil.BigD(tdBytes)
127-
}
128-
129-
if err := s.ListEnd(); err != nil {
111+
if err := s.Decode(&extblock); err != nil {
130112
return err
131113
}
132-
133-
self.header = &header
134-
self.uncles = uncleHeaders
135-
self.transactions = transactions
136-
114+
self.header = extblock.Header
115+
self.uncles = extblock.Uncles
116+
self.transactions = extblock.Txs
117+
self.Td = extblock.TD
137118
return nil
138119
}
139120

@@ -189,23 +170,35 @@ func (self *Block) RlpDataForStorage() interface{} {
189170
// Header accessors (add as you need them)
190171
func (self *Block) Number() *big.Int { return self.header.Number }
191172
func (self *Block) NumberU64() uint64 { return self.header.Number.Uint64() }
192-
func (self *Block) ParentHash() []byte { return self.header.ParentHash }
193173
func (self *Block) Bloom() []byte { return self.header.Bloom }
194174
func (self *Block) Coinbase() []byte { return self.header.Coinbase }
195175
func (self *Block) Time() int64 { return int64(self.header.Time) }
196176
func (self *Block) GasLimit() *big.Int { return self.header.GasLimit }
197177
func (self *Block) GasUsed() *big.Int { return self.header.GasUsed }
198-
func (self *Block) Hash() []byte { return self.header.Hash() }
199178
func (self *Block) Trie() *ptrie.Trie { return ptrie.New(self.header.Root, ethutil.Config.Db) }
179+
func (self *Block) SetRoot(root []byte) { self.header.Root = root }
200180
func (self *Block) State() *state.StateDB { return state.New(self.Trie()) }
201181
func (self *Block) Size() ethutil.StorageSize { return ethutil.StorageSize(len(ethutil.Encode(self))) }
202-
func (self *Block) SetRoot(root []byte) { self.header.Root = root }
203182

204-
// Implement block.Pow
183+
// Implement pow.Block
205184
func (self *Block) Difficulty() *big.Int { return self.header.Difficulty }
206185
func (self *Block) N() []byte { return self.header.Nonce }
207-
func (self *Block) HashNoNonce() []byte {
208-
return crypto.Sha3(ethutil.Encode(self.header.rlpData(false)))
186+
func (self *Block) HashNoNonce() []byte { return self.header.HashNoNonce() }
187+
188+
func (self *Block) Hash() []byte {
189+
if self.HeaderHash != nil {
190+
return self.HeaderHash
191+
} else {
192+
return self.header.Hash()
193+
}
194+
}
195+
196+
func (self *Block) ParentHash() []byte {
197+
if self.ParentHeaderHash != nil {
198+
return self.ParentHeaderHash
199+
} else {
200+
return self.header.ParentHash
201+
}
209202
}
210203

211204
func (self *Block) String() string {

0 commit comments

Comments
 (0)