diff options
author | Wei-Ning Huang <w@dexon.org> | 2019-02-25 19:35:06 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | 4ce8adb190ae3351a507be54f38afa6b47ce18a3 (patch) | |
tree | 585b6f4bb5ee06b0fdab0f8e68f34e15b6ae0fed /dex/governance.go | |
parent | 0ac79d780ba63c574d648552f887c9411fdd76fe (diff) | |
download | dexon-4ce8adb190ae3351a507be54f38afa6b47ce18a3.tar dexon-4ce8adb190ae3351a507be54f38afa6b47ce18a3.tar.gz dexon-4ce8adb190ae3351a507be54f38afa6b47ce18a3.tar.bz2 dexon-4ce8adb190ae3351a507be54f38afa6b47ce18a3.tar.lz dexon-4ce8adb190ae3351a507be54f38afa6b47ce18a3.tar.xz dexon-4ce8adb190ae3351a507be54f38afa6b47ce18a3.tar.zst dexon-4ce8adb190ae3351a507be54f38afa6b47ce18a3.zip |
core: vm: flatten governance
Diffstat (limited to 'dex/governance.go')
-rw-r--r-- | dex/governance.go | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/dex/governance.go b/dex/governance.go index 56d08975e..d9cf8fb65 100644 --- a/dex/governance.go +++ b/dex/governance.go @@ -67,7 +67,7 @@ func NewDexconGovernance(backend *DexAPIBackend, chainConfig *params.ChainConfig // DexconConfiguration return raw config in state. func (d *DexconGovernance) DexconConfiguration(round uint64) *params.DexconConfig { - return d.GetGovStateHelperAtRound(round).Configuration() + return d.GetStateForConfigAtRound(round).Configuration() } func (d *DexconGovernance) sendGovTx(ctx context.Context, data []byte) error { @@ -107,13 +107,32 @@ func (d *DexconGovernance) sendGovTx(ctx context.Context, data []byte) error { // CRS returns the CRS for a given round. func (d *DexconGovernance) CRS(round uint64) coreCommon.Hash { - s := d.GetHeadHelper() - return coreCommon.Hash(s.CRS(big.NewInt(int64(round)))) + 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) LenCRS() uint64 { - s := d.GetHeadHelper() - return s.LenCRS().Uint64() +func (d *DexconGovernance) CRSRound() uint64 { + return d.GetHeadState().CRSRound().Uint64() } // ProposeCRS send proposals of a new CRS @@ -132,7 +151,7 @@ func (d *DexconGovernance) ProposeCRS(round uint64, signedCRS []byte) { // NodeSet returns the current node set. func (d *DexconGovernance) NodeSet(round uint64) []coreCrypto.PublicKey { - s := d.GetGovStateHelperAtRound(round) + s := d.GetStateForConfigAtRound(round) var pks []coreCrypto.PublicKey for _, n := range s.QualifiedNodes() { |