Skip to content

Commit 52b4e51

Browse files
committed
Merge branch 'release/0.9.24'
2 parents 13e662f + 0a85260 commit 52b4e51

24 files changed

+6848
-4751
lines changed

cmd/geth/js.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ var net = web3.net;
141141
utils.Fatalf("Error setting namespaces: %v", err)
142142
}
143143

144-
js.re.Eval(globalRegistrar + "registrar = new GlobalRegistrar(\"" + globalRegistrarAddr + "\");")
144+
js.re.Eval(globalRegistrar + "registrar = GlobalRegistrar.at(\"" + globalRegistrarAddr + "\");")
145145
}
146146

147147
var ds, _ = docserver.New("/")

cmd/geth/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import _ "net/http/pprof"
4848

4949
const (
5050
ClientIdentifier = "Geth"
51-
Version = "0.9.23"
51+
Version = "0.9.24"
5252
)
5353

5454
var (

core/blocks.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ import "github.com/ethereum/go-ethereum/common"
44

55
var badHashes = []common.Hash{
66
common.HexToHash("f269c503aed286caaa0d114d6a5320e70abbc2febe37953207e76a2873f2ba79"),
7+
common.HexToHash("38f5bbbffd74804820ffa4bab0cd540e9de229725afb98c1a7e57936f4a714bc"),
78
}

core/vm/disasm.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package vm
2+
3+
import "fmt"
4+
5+
func Disasm(code []byte) []string {
6+
var out []string
7+
for pc := uint64(0); pc < uint64(len(code)); pc++ {
8+
op := OpCode(code[pc])
9+
out = append(out, op.String())
10+
11+
switch op {
12+
case PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32:
13+
a := uint64(op) - uint64(PUSH1) + 1
14+
out = append(out, fmt.Sprintf("0x%x", code[pc+1:pc+1+a]))
15+
16+
pc += a
17+
}
18+
}
19+
20+
return out
21+
}

core/vm/memory.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package vm
22

3-
import (
4-
"fmt"
5-
6-
"github.com/ethereum/go-ethereum/common"
7-
)
3+
import "fmt"
84

95
type Memory struct {
106
store []byte
@@ -24,7 +20,7 @@ func (m *Memory) Set(offset, size uint64, value []byte) {
2420
// It's possible the offset is greater than 0 and size equals 0. This is because
2521
// the calcMemSize (common.go) could potentially return 0 when size is zero (NO-OP)
2622
if size > 0 {
27-
copy(m.store[offset:offset+size], common.RightPadBytes(value, int(size)))
23+
copy(m.store[offset:offset+size], value)
2824
}
2925
}
3026

core/vm/vm.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
128128
mem.Resize(newMemSize.Uint64())
129129

130130
switch op {
131-
// 0x20 range
132131
case ADD:
133132
x, y := stack.pop(), stack.pop()
134133
self.Printf(" %v + %v", y, x)
@@ -142,7 +141,7 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
142141
stack.push(base)
143142
case SUB:
144143
x, y := stack.pop(), stack.pop()
145-
self.Printf(" %v - %v", y, x)
144+
self.Printf(" %v - %v", x, y)
146145

147146
base.Sub(x, y)
148147

@@ -268,9 +267,6 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
268267
}
269268
case NOT:
270269
stack.push(U256(new(big.Int).Not(stack.pop())))
271-
//base.Sub(Pow256, stack.pop()).Sub(base, common.Big1)
272-
//base = U256(base)
273-
//stack.push(base)
274270
case LT:
275271
x, y := stack.pop(), stack.pop()
276272
self.Printf(" %v < %v", x, y)
@@ -329,7 +325,6 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
329325
stack.push(common.BigTrue)
330326
}
331327

332-
// 0x10 range
333328
case AND:
334329
x, y := stack.pop(), stack.pop()
335330
self.Printf(" %v & %v", y, x)
@@ -390,15 +385,13 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
390385

391386
stack.push(base)
392387

393-
// 0x20 range
394388
case SHA3:
395389
offset, size := stack.pop(), stack.pop()
396390
data := crypto.Sha3(mem.Get(offset.Int64(), size.Int64()))
397391

398392
stack.push(common.BigD(data))
399393

400394
self.Printf(" => (%v) %x", size, data)
401-
// 0x30 range
402395
case ADDRESS:
403396
stack.push(common.Bytes2Big(context.Address().Bytes()))
404397

@@ -486,7 +479,6 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
486479

487480
self.Printf(" => %x", context.Price)
488481

489-
// 0x40 range
490482
case BLOCKHASH:
491483
num := stack.pop()
492484

@@ -527,7 +519,6 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
527519

528520
stack.push(self.env.GasLimit())
529521

530-
// 0x50 range
531522
case PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32:
532523
a := big.NewInt(int64(op - PUSH1 + 1))
533524
byts := getData(code, new(big.Int).Add(pc, big.NewInt(1)), a)
@@ -553,12 +544,11 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
553544
topics := make([]common.Hash, n)
554545
mStart, mSize := stack.pop(), stack.pop()
555546
for i := 0; i < n; i++ {
556-
topics[i] = common.BigToHash(stack.pop()) //common.LeftPadBytes(stack.pop().Bytes(), 32)
547+
topics[i] = common.BigToHash(stack.pop())
557548
}
558549

559550
data := mem.Get(mStart.Int64(), mSize.Int64())
560551
log := state.NewLog(context.Address(), topics, data, self.env.BlockNumber().Uint64())
561-
//log := &Log{context.Address(), topics, data, self.env.BlockNumber().Uint64()}
562552
self.env.AddLog(log)
563553

564554
self.Printf(" => %v", log)
@@ -568,7 +558,7 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
568558
stack.push(val)
569559

570560
self.Printf(" => 0x%x", val.Bytes())
571-
case MSTORE: // Store the value at stack top-1 in to memory at location stack top
561+
case MSTORE:
572562
// pop value of the stack
573563
mStart, val := stack.pop(), stack.pop()
574564
mem.Set(mStart.Uint64(), 32, common.BigToBytes(val, 256))
@@ -614,15 +604,13 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
614604

615605
case JUMPDEST:
616606
case PC:
617-
//stack.push(big.NewInt(int64(pc)))
618607
stack.push(pc)
619608
case MSIZE:
620609
stack.push(big.NewInt(int64(mem.Len())))
621610
case GAS:
622611
stack.push(context.Gas)
623612

624613
self.Printf(" => %x", context.Gas)
625-
// 0x60 range
626614
case CREATE:
627615

628616
var (

eth/downloader/downloader.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ type Downloader struct {
9393
cancelLock sync.RWMutex // Lock to protect the cancel channel in delivers
9494
}
9595

96+
// Block is an origin-tagged blockchain block.
97+
type Block struct {
98+
RawBlock *types.Block
99+
OriginPeer string
100+
}
101+
96102
func New(mux *event.TypeMux, hasBlock hashCheckFn, getBlock getBlockFn) *Downloader {
97103
downloader := &Downloader{
98104
mux: mux,
@@ -177,7 +183,7 @@ func (d *Downloader) Synchronise(id string, hash common.Hash) error {
177183
}
178184

179185
// TakeBlocks takes blocks from the queue and yields them to the caller.
180-
func (d *Downloader) TakeBlocks() types.Blocks {
186+
func (d *Downloader) TakeBlocks() []*Block {
181187
return d.queue.TakeBlocks()
182188
}
183189

eth/downloader/downloader_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ func (dl *downloadTester) sync(peerId string, head common.Hash) error {
8888
// syncTake is starts synchronising with a remote peer, but concurrently it also
8989
// starts fetching blocks that the downloader retrieved. IT blocks until both go
9090
// routines terminate.
91-
func (dl *downloadTester) syncTake(peerId string, head common.Hash) (types.Blocks, error) {
91+
func (dl *downloadTester) syncTake(peerId string, head common.Hash) ([]*Block, error) {
9292
// Start a block collector to take blocks as they become available
9393
done := make(chan struct{})
94-
took := []*types.Block{}
94+
took := []*Block{}
9595
go func() {
9696
for running := true; running; {
9797
select {
@@ -349,7 +349,7 @@ func TestNonExistingParentAttack(t *testing.T) {
349349
if len(bs) != 1 {
350350
t.Fatalf("retrieved block mismatch: have %v, want %v", len(bs), 1)
351351
}
352-
if tester.hasBlock(bs[0].ParentHash()) {
352+
if tester.hasBlock(bs[0].RawBlock.ParentHash()) {
353353
t.Fatalf("tester knows about the unknown hash")
354354
}
355355
tester.downloader.Cancel()
@@ -364,7 +364,7 @@ func TestNonExistingParentAttack(t *testing.T) {
364364
if len(bs) != 1 {
365365
t.Fatalf("retrieved block mismatch: have %v, want %v", len(bs), 1)
366366
}
367-
if !tester.hasBlock(bs[0].ParentHash()) {
367+
if !tester.hasBlock(bs[0].RawBlock.ParentHash()) {
368368
t.Fatalf("tester doesn't know about the origin hash")
369369
}
370370
}

eth/downloader/queue.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type queue struct {
3636
pendPool map[string]*fetchRequest // Currently pending block retrieval operations
3737

3838
blockPool map[common.Hash]int // Hash-set of the downloaded data blocks, mapping to cache indexes
39-
blockCache []*types.Block // Downloaded but not yet delivered blocks
39+
blockCache []*Block // Downloaded but not yet delivered blocks
4040
blockOffset int // Offset of the first cached block in the block-chain
4141

4242
lock sync.RWMutex
@@ -148,7 +148,7 @@ func (q *queue) Insert(hashes []common.Hash) []common.Hash {
148148

149149
// GetHeadBlock retrieves the first block from the cache, or nil if it hasn't
150150
// been downloaded yet (or simply non existent).
151-
func (q *queue) GetHeadBlock() *types.Block {
151+
func (q *queue) GetHeadBlock() *Block {
152152
q.lock.RLock()
153153
defer q.lock.RUnlock()
154154

@@ -159,7 +159,7 @@ func (q *queue) GetHeadBlock() *types.Block {
159159
}
160160

161161
// GetBlock retrieves a downloaded block, or nil if non-existent.
162-
func (q *queue) GetBlock(hash common.Hash) *types.Block {
162+
func (q *queue) GetBlock(hash common.Hash) *Block {
163163
q.lock.RLock()
164164
defer q.lock.RUnlock()
165165

@@ -176,18 +176,18 @@ func (q *queue) GetBlock(hash common.Hash) *types.Block {
176176
}
177177

178178
// TakeBlocks retrieves and permanently removes a batch of blocks from the cache.
179-
func (q *queue) TakeBlocks() types.Blocks {
179+
func (q *queue) TakeBlocks() []*Block {
180180
q.lock.Lock()
181181
defer q.lock.Unlock()
182182

183183
// Accumulate all available blocks
184-
var blocks types.Blocks
184+
blocks := []*Block{}
185185
for _, block := range q.blockCache {
186186
if block == nil {
187187
break
188188
}
189189
blocks = append(blocks, block)
190-
delete(q.blockPool, block.Hash())
190+
delete(q.blockPool, block.RawBlock.Hash())
191191
}
192192
// Delete the blocks from the slice and let them be garbage collected
193193
// without this slice trick the blocks would stay in memory until nil
@@ -312,8 +312,10 @@ func (q *queue) Deliver(id string, blocks []*types.Block) (err error) {
312312
return ErrInvalidChain
313313
}
314314
// Otherwise merge the block and mark the hash block
315-
q.blockCache[index] = block
316-
315+
q.blockCache[index] = &Block{
316+
RawBlock: block,
317+
OriginPeer: id,
318+
}
317319
delete(request.Hashes, hash)
318320
delete(q.hashPool, hash)
319321
q.blockPool[hash] = int(block.NumberU64())
@@ -342,6 +344,6 @@ func (q *queue) Alloc(offset int) {
342344
size = blockCacheLimit
343345
}
344346
if len(q.blockCache) < size {
345-
q.blockCache = append(q.blockCache, make([]*types.Block, size-len(q.blockCache))...)
347+
q.blockCache = append(q.blockCache, make([]*Block, size-len(q.blockCache))...)
346348
}
347349
}

eth/handler.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ func NewProtocolManager(protocolVersion, networkId int, mux *event.TypeMux, txpo
9292
return manager
9393
}
9494

95-
func (pm *ProtocolManager) removePeer(peer *peer) {
95+
func (pm *ProtocolManager) removePeer(id string) {
9696
// Unregister the peer from the downloader
97-
pm.downloader.UnregisterPeer(peer.id)
97+
pm.downloader.UnregisterPeer(id)
9898

9999
// Remove the peer from the Ethereum peer set too
100-
glog.V(logger.Detail).Infoln("Removing peer", peer.id)
101-
if err := pm.peers.Unregister(peer.id); err != nil {
100+
glog.V(logger.Detail).Infoln("Removing peer", id)
101+
if err := pm.peers.Unregister(id); err != nil {
102102
glog.V(logger.Error).Infoln("Removal failed:", err)
103103
}
104104
}
@@ -148,7 +148,7 @@ func (pm *ProtocolManager) handle(p *peer) error {
148148
glog.V(logger.Error).Infoln("Addition failed:", err)
149149
return err
150150
}
151-
defer pm.removePeer(p)
151+
defer pm.removePeer(p.id)
152152

153153
if err := pm.downloader.RegisterPeer(p.id, p.recentHash, p.requestHashes, p.requestBlocks); err != nil {
154154
return err
@@ -315,7 +315,7 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
315315
if _, err := self.chainman.InsertChain(types.Blocks{request.Block}); err != nil {
316316
glog.V(logger.Error).Infoln("removed peer (", p.id, ") due to block error")
317317

318-
self.removePeer(p)
318+
self.removePeer(p.id)
319319

320320
return nil
321321
}

0 commit comments

Comments
 (0)