Skip to content

Commit 8f94931

Browse files
authored
Merge pull request #225 from ellcrys/dev
Smarter Chain Re-organisation
2 parents e890459 + f57b64e commit 8f94931

Some content is hidden

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

41 files changed

+3560
-465
lines changed

.circleci/config.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
dist: xenial
2+
language: go
3+
go:
4+
- 1.12.4
5+
before_install:
6+
- curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
7+
- go get github.com/onsi/ginkgo/ginkgo
8+
install:
9+
- dep ensure -v
10+
script:
11+
- ginkgo -v -race ./...
12+
cache:
13+
directories:
14+
- vendor
15+
notifications:
16+
slack:
17+
secure: a/JzDKjun3yXPLhxLFzgeE7EmbbS+Mo//BRsjsUHzMzhtzlkBnx+cwDjCKEl81k69eKCbgM7+zYL0q7p5CtlQH8maz6f/akB+rl+xSSV/cmRKKQeCH+Ht9q7qr8nkW0q7UaomK8bWml3ODTl9iEOfxUt6gJK3uufXEFJ8dMtbU73IEitUDFNfSnXHt1hBMjbfNu52aFcbzwDJciYdNN5n6uw2kd0fXSIbWfOwjqUJGQvzH5zFmE8M6yQ6f9U45RqBmNAA7rWkOK0qDTiA0d/DnAytLrWVMe+PT78/gfMpXXqMilooEOV7RLufOZjAsnAQDxrVuuRdmnBwRnHHe9I+uabW+1iFkDXwppztpmx54FO5+r6pePbQlNkOWuAkGjj7KXm3kEKAvh13uI/7lYbUur/jVIe8g/MOnWhm48c39vfaSnyq3teHzbYVfePYbzzNHDMG604o/AurXFOUNLkN1GzcREg7pzFSatcATkShubu2DmAncxPGC33M0Ci6CzbcpuCb8KciUX/x2PGyy5pOmo4nEX5N9pFneQV/ggpvEEShh9LQOkVWoWOftwV/5j/NsLmolOkxMoomh/niGsb1GQUr/jLmwFZ8ppNI0fQGeiMWW2Ov0vjQ+dFvAiOU9GxKEEWKtegrLaxGubSm1i7XtUvCMdro7cb3UB1ObNL8S8=

Gopkg.lock

Lines changed: 25 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,6 @@
145145
branch = "master"
146146
name = "github.com/ncodes/go-prettyjson"
147147

148-
[[constraint]]
149-
branch = "master"
150-
name = "github.com/ncodes/whereami"
151-
152148
[[constraint]]
153149
branch = "master"
154150
name = "github.com/olebedev/emitter"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Elld - Official Ellcrys Client
44
[![GoDoc](https://godoc.org/github.com/ellcrys/elld?status.svg)](https://godoc.org/github.com/ellcrys/elld)
5-
[![CircleCI](https://circleci.com/gh/ellcrys/elld/tree/master.svg?style=svg)](https://circleci.com/gh/ellcrys/elld/tree/master)
5+
[![Build Status](https://travis-ci.org/ellcrys/elld.svg?branch=master)](https://travis-ci.org/ellcrys/elld)
66
[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/ellnet)
77
[![Go Report Card](https://goreportcard.com/badge/github.com/ellcrys/elld)](https://goreportcard.com/report/github.com/ellcrys/elld)
88

blockchain/blockchain.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"sync"
99
"time"
1010

11-
"github.com/ellcrys/elld/util/activeobject"
12-
1311
"github.com/ellcrys/elld/crypto"
1412
"github.com/syndtr/goleveldb/leveldb"
1513

@@ -35,6 +33,11 @@ const (
3533
MaxRejectedBlocksCacheSize = 100
3634
)
3735

36+
var (
37+
// GenesisBlockFileName is the name of the file that contains the genesis block
38+
GenesisBlockFileName = "genesis.json"
39+
)
40+
3841
// Blockchain represents the Ellcrys blockchain. It provides
3942
// functionalities for interacting with the underlying database
4043
// and primitives.
@@ -76,9 +79,11 @@ type Blockchain struct {
7679
// events or broadcast events about its state
7780
eventEmitter *emitter.Emitter
7881

79-
// activeObj provides active object pattern for handling
80-
// function calls
81-
activeObj *activeobject.ActiveObject
82+
// skipDecideBestChain skips the operation to decide which chain is the best
83+
// when a block is processed.
84+
// Note: Used to prevent re-organisation when creating
85+
// and assembling blocks into desired chains in integration test.
86+
skipDecideBestChain bool
8287

8388
// chl is a lock for chain events
8489
chl *sync.RWMutex
@@ -111,7 +116,6 @@ func New(txPool types.TxPool, cfg *config.EngineConfig, log logger.Logger) *Bloc
111116
bc.orphanBlocks = cache.NewCache(MaxOrphanBlocksCacheSize)
112117
bc.rejectedBlocks = cache.NewCache(MaxRejectedBlocksCacheSize)
113118
bc.eventEmitter = &emitter.Emitter{}
114-
bc.activeObj = activeobject.NewActiveObject()
115119
return bc
116120
}
117121

@@ -176,7 +180,7 @@ func (b *Blockchain) Up() error {
176180
// been set, we attempt to load it from the
177181
// genesis.json file.
178182
if b.genesisBlock == nil {
179-
b.genesisBlock, err = LoadBlockFromFile("genesis.json")
183+
b.genesisBlock, err = LoadBlockFromFile(GenesisBlockFileName)
180184
if err != nil {
181185
return err
182186
}
@@ -222,6 +226,9 @@ func (b *Blockchain) Up() error {
222226
b.log.Info("Known branches have been loaded", "NumBranches", numChains)
223227
}
224228

229+
// Set the root chain and make it the initial main chain
230+
b.bestChain = b.getRootChain()
231+
225232
// Using the best chain rule, we mush select the best chain
226233
// and set it as the current bestChain.
227234
err = b.decideBestChain()
@@ -232,6 +239,19 @@ func (b *Blockchain) Up() error {
232239
return nil
233240
}
234241

242+
// getRootChain finds the root chain of the tree.
243+
// This is usually the main chain and it has no branch.
244+
func (b *Blockchain) getRootChain() *Chain {
245+
b.chl.RLock()
246+
defer b.chl.RUnlock()
247+
for _, c := range b.chains {
248+
if !c.HasParent() {
249+
return c
250+
}
251+
}
252+
return nil
253+
}
254+
235255
// getBlockByHash finds and returns a block by hash only
236256
// SetEventEmitter sets the event emitter
237257
func (b *Blockchain) SetEventEmitter(ee *emitter.Emitter) {

0 commit comments

Comments
 (0)