aboutsummaryrefslogtreecommitdiffstats
path: root/dex/downloader
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-02-25 19:35:06 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:22 +0800
commitbfac6dd5391b871d148713014f2694d31d9b6ea4 (patch)
treeb80909c9f5ad6f6021b3ebacff51c73469401765 /dex/downloader
parent2b2396b6bce0f21b515ac2d38556f6dca08b1770 (diff)
downloadgo-tangerine-bfac6dd5391b871d148713014f2694d31d9b6ea4.tar.gz
go-tangerine-bfac6dd5391b871d148713014f2694d31d9b6ea4.tar.zst
go-tangerine-bfac6dd5391b871d148713014f2694d31d9b6ea4.zip
core: vm: flatten governance
Diffstat (limited to 'dex/downloader')
-rw-r--r--dex/downloader/downloader.go11
-rw-r--r--dex/downloader/testchain_test.go76
2 files changed, 26 insertions, 61 deletions
diff --git a/dex/downloader/downloader.go b/dex/downloader/downloader.go
index e15844668..3d3a78e18 100644
--- a/dex/downloader/downloader.go
+++ b/dex/downloader/downloader.go
@@ -496,17 +496,6 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, number ui
}
d.verifierCache = dexCore.NewTSigVerifierCache(d.gov, 5)
-
- // warm up verifierCache
- if originHeader.Round > 0 {
- ok, err := d.verifierCache.Update(originHeader.Round - 1)
- if err != nil {
- return err
- }
- if !ok {
- return fmt.Errorf("can not update verifier cache")
- }
- }
}
// Initiate the sync using a concurrent header and content retrieval algorithm
diff --git a/dex/downloader/testchain_test.go b/dex/downloader/testchain_test.go
index 73d4863a5..722159bc0 100644
--- a/dex/downloader/testchain_test.go
+++ b/dex/downloader/testchain_test.go
@@ -21,6 +21,9 @@ import (
"fmt"
"math/big"
+ dexCore "github.com/dexon-foundation/dexon-consensus/core"
+ coreTypes "github.com/dexon-foundation/dexon-consensus/core/types"
+
"github.com/dexon-foundation/dexon/common"
"github.com/dexon-foundation/dexon/consensus/dexcon"
"github.com/dexon-foundation/dexon/core"
@@ -66,23 +69,23 @@ func genesisBlockForTesting(db ethdb.Database,
Staked: new(big.Int),
},
nodeaddr1: {
- Balance: new(big.Int).Mul(big.NewInt(1000), ether),
- Staked: new(big.Int).Mul(big.NewInt(500), ether),
+ Balance: new(big.Int).Mul(big.NewInt(2e6), ether),
+ Staked: new(big.Int).Mul(big.NewInt(1e6), ether),
PublicKey: crypto.FromECDSAPub(&nodekey1.PublicKey),
},
nodeaddr2: {
- Balance: new(big.Int).Mul(big.NewInt(1000), ether),
- Staked: new(big.Int).Mul(big.NewInt(500), ether),
+ Balance: new(big.Int).Mul(big.NewInt(2e6), ether),
+ Staked: new(big.Int).Mul(big.NewInt(1e6), ether),
PublicKey: crypto.FromECDSAPub(&nodekey2.PublicKey),
},
nodeaddr3: {
- Balance: new(big.Int).Mul(big.NewInt(1000), ether),
- Staked: new(big.Int).Mul(big.NewInt(500), ether),
+ Balance: new(big.Int).Mul(big.NewInt(2e6), ether),
+ Staked: new(big.Int).Mul(big.NewInt(1e6), ether),
PublicKey: crypto.FromECDSAPub(&nodekey3.PublicKey),
},
nodeaddr4: {
- Balance: new(big.Int).Mul(big.NewInt(1000), ether),
- Staked: new(big.Int).Mul(big.NewInt(500), ether),
+ Balance: new(big.Int).Mul(big.NewInt(2e6), ether),
+ Staked: new(big.Int).Mul(big.NewInt(1e6), ether),
PublicKey: crypto.FromECDSAPub(&nodekey4.PublicKey),
},
},
@@ -166,50 +169,23 @@ func (tc *testChain) generate(n int, seed byte, parent *types.Block, nodes *dexc
blocks, receipts := core.GenerateDexonChain(params.TestnetChainConfig, parent, engine, testDB, n, func(i int, block *core.DexonBlockGen) {
block.SetCoinbase(common.Address{seed})
- if round == 0 {
- switch i {
- case 1:
- testNodes.RunDKG(round, 2)
- // Add DKG MasterPublicKeys
- for _, node := range testNodes.Nodes(round) {
- data, err := vm.PackAddDKGMasterPublicKey(round, node.MasterPublicKey(round))
- if err != nil {
- panic(err)
- }
- addTx(block, node, data)
- }
- case 2:
- // Add DKG MPKReady
- for _, node := range testNodes.Nodes(round) {
- data, err := vm.PackAddDKGMPKReady(round, node.DKGMPKReady(round))
- if err != nil {
- panic(err)
- }
- addTx(block, node, data)
- }
- case 3:
- // Add DKG Finalize
- for _, node := range testNodes.Nodes(round) {
- data, err := vm.PackAddDKGFinalize(round, node.DKGFinalize(round))
- if err != nil {
- panic(err)
- }
- addTx(block, node, data)
- }
- }
- }
-
+ block.SetPosition(coreTypes.Position{
+ Round: round,
+ Height: uint64(i),
+ })
half := roundInterval / 2
switch i % roundInterval {
case half:
- // Sign current CRS to geneate the next round CRS and propose it.
- testNodes.SignCRS(round)
- node := testNodes.Nodes(round)[0]
- data, err := vm.PackProposeCRS(round, testNodes.SignedCRS(round+1))
- if err != nil {
- panic(err)
+ if round >= dexCore.DKGDelayRound {
+ // Sign current CRS to geneate the next round CRS and propose it.
+ testNodes.SignCRS(round)
+ node := testNodes.Nodes(round)[0]
+ data, err := vm.PackProposeCRS(round, testNodes.SignedCRS(round+1))
+ if err != nil {
+ panic(err)
+ }
+ addTx(block, node, data)
}
- addTx(block, node, data)
case half + 1:
// Run the DKG for next round.
testNodes.RunDKG(round+1, 2)
@@ -356,13 +332,13 @@ func (g *govStateFetcher) SnapshotRound(round uint64, root common.Hash) {
g.rootByRound[round] = root
}
-func (g *govStateFetcher) GetGovStateHelperAtRound(round uint64) *vm.GovernanceStateHelper {
+func (g *govStateFetcher) GetStateForConfigAtRound(round uint64) *vm.GovernanceState {
if root, ok := g.rootByRound[round]; ok {
s, err := state.New(root, g.db)
if err != nil {
panic(err)
}
- return &vm.GovernanceStateHelper{s}
+ return &vm.GovernanceState{s}
}
return nil
}