diff options
author | Wei-Ning Huang <w@dexon.org> | 2019-03-20 11:55:01 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:58 +0800 |
commit | bbd2910687e9e5cd5c52e887f837f5c992ba2261 (patch) | |
tree | 5b76316f47ca4437fab3e0ae29dee4a112e2d805 /dex/governance.go | |
parent | 614cca7f39b8d63a5da938e56509e6fa5fc467cf (diff) | |
download | go-tangerine-bbd2910687e9e5cd5c52e887f837f5c992ba2261.tar go-tangerine-bbd2910687e9e5cd5c52e887f837f5c992ba2261.tar.gz go-tangerine-bbd2910687e9e5cd5c52e887f837f5c992ba2261.tar.bz2 go-tangerine-bbd2910687e9e5cd5c52e887f837f5c992ba2261.tar.lz go-tangerine-bbd2910687e9e5cd5c52e887f837f5c992ba2261.tar.xz go-tangerine-bbd2910687e9e5cd5c52e887f837f5c992ba2261.tar.zst go-tangerine-bbd2910687e9e5cd5c52e887f837f5c992ba2261.zip |
consensus: dexcon: disqualify dead node (#280)
Since a qualified node might fail stopped, we need to remove them from
qualified nodes to maintain network integrity. We do this by inspect the
previous round to see if there are dead nodes. A dead node is a notary
set node that does not propose any block in the previous round. We
disqualify them by fining them so their staked value is 1 wei below
minStake. This make them unqualified for being notary set in the follow
on rounds.
Diffstat (limited to 'dex/governance.go')
-rw-r--r-- | dex/governance.go | 99 |
1 files changed, 4 insertions, 95 deletions
diff --git a/dex/governance.go b/dex/governance.go index c2f2918b1..0d6ca0eba 100644 --- a/dex/governance.go +++ b/dex/governance.go @@ -20,13 +20,8 @@ package dex import ( "context" "crypto/ecdsa" - "encoding/hex" "math/big" - coreCommon "github.com/dexon-foundation/dexon-consensus/common" - dexCore "github.com/dexon-foundation/dexon-consensus/core" - coreCrypto "github.com/dexon-foundation/dexon-consensus/core/crypto" - coreEcdsa "github.com/dexon-foundation/dexon-consensus/core/crypto/ecdsa" coreTypes "github.com/dexon-foundation/dexon-consensus/core/types" dkgTypes "github.com/dexon-foundation/dexon-consensus/core/types/dkg" @@ -42,11 +37,10 @@ import ( type DexconGovernance struct { *core.Governance - b *DexAPIBackend - chainConfig *params.ChainConfig - privateKey *ecdsa.PrivateKey - address common.Address - nodeSetCache *dexCore.NodeSetCache + b *DexAPIBackend + chainConfig *params.ChainConfig + privateKey *ecdsa.PrivateKey + address common.Address } // NewDexconGovernance returns a governance implementation of the DEXON @@ -61,7 +55,6 @@ func NewDexconGovernance(backend *DexAPIBackend, chainConfig *params.ChainConfig privateKey: privKey, address: crypto.PubkeyToAddress(privKey.PublicKey), } - g.nodeSetCache = dexCore.NewNodeSetCache(g) return g } @@ -110,36 +103,10 @@ func (d *DexconGovernance) sendGovTx(ctx context.Context, data []byte) error { return d.b.SendTx(ctx, tx) } -// CRS returns the CRS for a given round. -func (d *DexconGovernance) CRS(round uint64) coreCommon.Hash { - if round <= dexCore.DKGDelayRound { - s := d.GetStateAtRound(0) - crs := s.CRS() - for i := uint64(0); i < round; i++ { - crs = crypto.Keccak256Hash(crs[:]) - } - return coreCommon.Hash(crs) - } - if round > d.CRSRound() { - return coreCommon.Hash{} - } - var s *vm.GovernanceState - if round == d.CRSRound() { - s = d.GetHeadState() - } else { - s = d.GetStateAtRound(round) - } - return coreCommon.Hash(s.CRS()) -} - func (d *DexconGovernance) Round() uint64 { return d.b.CurrentBlock().Round() } -func (d *DexconGovernance) CRSRound() uint64 { - return d.GetHeadState().CRSRound().Uint64() -} - // ProposeCRS send proposals of a new CRS func (d *DexconGovernance) ProposeCRS(round uint64, signedCRS []byte) { data, err := vm.PackProposeCRS(round, signedCRS) @@ -154,21 +121,6 @@ func (d *DexconGovernance) ProposeCRS(round uint64, signedCRS []byte) { } } -// NodeSet returns the current node set. -func (d *DexconGovernance) NodeSet(round uint64) []coreCrypto.PublicKey { - s := d.GetStateForConfigAtRound(round) - var pks []coreCrypto.PublicKey - - for _, n := range s.QualifiedNodes() { - pk, err := coreEcdsa.NewPublicKeyFromByteSlice(n.PublicKey) - if err != nil { - panic(err) - } - pks = append(pks, pk) - } - return pks -} - // AddDKGComplaint adds a DKGComplaint. func (d *DexconGovernance) AddDKGComplaint(round uint64, complaint *dkgTypes.Complaint) { data, err := vm.PackAddDKGComplaint(round, complaint) @@ -253,49 +205,6 @@ func (d *DexconGovernance) ReportForkBlock(block1, block2 *coreTypes.Block) { } } -func (d *DexconGovernance) NotarySet(round uint64) (map[string]struct{}, error) { - notarySet, err := d.nodeSetCache.GetNotarySet(round) - if err != nil { - return nil, err - } - - r := make(map[string]struct{}, len(notarySet)) - for id := range notarySet { - if key, exists := d.nodeSetCache.GetPublicKey(id); exists { - r[hex.EncodeToString(key.Bytes())] = struct{}{} - } - } - return r, nil -} - -func (d *DexconGovernance) NotarySetAddresses(round uint64) (map[common.Address]struct{}, error) { - notarySet, err := d.nodeSetCache.GetNotarySet(round) - if err != nil { - return nil, err - } - - r := make(map[common.Address]struct{}, len(notarySet)) - for id := range notarySet { - r[vm.IdToAddress(id)] = struct{}{} - } - return r, nil -} - -func (d *DexconGovernance) DKGSet(round uint64) (map[string]struct{}, error) { - dkgSet, err := d.nodeSetCache.GetDKGSet(round) - if err != nil { - return nil, err - } - - r := make(map[string]struct{}, len(dkgSet)) - for id := range dkgSet { - if key, exists := d.nodeSetCache.GetPublicKey(id); exists { - r[hex.EncodeToString(key.Bytes())] = struct{}{} - } - } - return r, nil -} - func (d *DexconGovernance) ResetDKG(newSignedCRS []byte) { data, err := vm.PackResetDKG(newSignedCRS) if err != nil { |