aboutsummaryrefslogtreecommitdiffstats
path: root/simulation
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-07-31 18:46:24 +0800
committerGitHub <noreply@github.com>2018-07-31 18:46:24 +0800
commit3778e956013cad171cd5954686831e2598de3045 (patch)
treef1d38286fc55dbf20def9a49a67449961ce89b44 /simulation
parentc9cf5953512e4503f4781d6a441404ff9dfe5660 (diff)
downloadtangerine-consensus-3778e956013cad171cd5954686831e2598de3045.tar.gz
tangerine-consensus-3778e956013cad171cd5954686831e2598de3045.tar.zst
tangerine-consensus-3778e956013cad171cd5954686831e2598de3045.zip
blockdb: allow to dump blocks to json-encoded file
- Allow to dump blockdb to a json file - Compared to leveldb, a json file is easier to trace. - Add interfaces block database: - Close would be required by database that needs cleanup. - BlockIterator is required when we need to access 'all' blocks, adding a new method 'GetAll' as the constructor for iterators. - Remove GetByValidatorAndHeight from blockdb.Reader - This function is not used anywhere, to make interface minimum, remove it. - Fix typo: backend -> backed
Diffstat (limited to 'simulation')
-rw-r--r--simulation/simulation.go6
-rw-r--r--simulation/validator.go13
2 files changed, 9 insertions, 10 deletions
diff --git a/simulation/simulation.go b/simulation/simulation.go
index 2ea768e..8542051 100644
--- a/simulation/simulation.go
+++ b/simulation/simulation.go
@@ -51,14 +51,14 @@ func Run(configPath string) {
for i := 0; i < cfg.Validator.Num; i++ {
id := types.ValidatorID{Hash: common.NewRandomHash()}
- vs = append(vs, NewValidator(id, cfg.Validator, network, nil))
+ vs = append(vs, NewValidator(id, cfg.Validator, network))
}
} else if networkType == config.NetworkTypeTCPLocal {
for i := 0; i < cfg.Validator.Num; i++ {
id := types.ValidatorID{Hash: common.NewRandomHash()}
network := NewTCPNetwork(true, cfg.Networking.PeerServer)
go network.Start()
- vs = append(vs, NewValidator(id, cfg.Validator, network, nil))
+ vs = append(vs, NewValidator(id, cfg.Validator, network))
}
}
@@ -70,7 +70,7 @@ func Run(configPath string) {
id := types.ValidatorID{Hash: common.NewRandomHash()}
network := NewTCPNetwork(false, cfg.Networking.PeerServer)
go network.Start()
- v := NewValidator(id, cfg.Validator, network, nil)
+ v := NewValidator(id, cfg.Validator, network)
go v.Run()
vs = append(vs, v)
}
diff --git a/simulation/validator.go b/simulation/validator.go
index 27e02fb..fb8afed 100644
--- a/simulation/validator.go
+++ b/simulation/validator.go
@@ -20,8 +20,6 @@ package simulation
import (
"time"
- "github.com/syndtr/goleveldb/leveldb"
-
"github.com/dexon-foundation/dexon-consensus-core/blockdb"
"github.com/dexon-foundation/dexon-consensus-core/common"
"github.com/dexon-foundation/dexon-consensus-core/core"
@@ -35,7 +33,6 @@ type Validator struct {
app *SimApp
config config.Validator
- db *leveldb.DB
msgChannel chan interface{}
isFinished chan struct{}
@@ -51,16 +48,18 @@ type Validator struct {
func NewValidator(
id types.ValidatorID,
config config.Validator,
- network Network,
- db *leveldb.DB) *Validator {
+ network Network) *Validator {
app := NewSimApp(id, network)
- lattice := core.NewBlockLattice(blockdb.NewMemBackedBlockDB(), app)
+ db, err := blockdb.NewMemBackedBlockDB()
+ if err != nil {
+ panic(err)
+ }
+ lattice := core.NewBlockLattice(db, app)
return &Validator{
ID: id,
config: config,
network: network,
app: app,
- db: db,
lattice: lattice,
isFinished: make(chan struct{}),
}