From 9493109f2be4507605e6b17e406bf8fd147ab3c8 Mon Sep 17 00:00:00 2001 From: Wei-Ning Huang Date: Sun, 17 Mar 2019 09:12:50 +0800 Subject: dex: implement recovery mechanism (#258) * dex: implement recovery mechanism The DEXON recovery protocol allows us to use the Ethereum blockchain as a fallback consensus chain to coordinate recovery. * fix --- params/config.go | 37 +++++++++++++++++++++++++++++++++---- params/gen_dexcon_config.go | 12 ++++++------ 2 files changed, 39 insertions(+), 10 deletions(-) (limited to 'params') diff --git a/params/config.go b/params/config.go index 8cf986f55..4eefc8f08 100644 --- a/params/config.go +++ b/params/config.go @@ -75,6 +75,11 @@ var ( new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e5)), }, }, + Recovery: &RecoveryConfig{ + Contract: common.HexToAddress("0xcb4bb8ae26b2ebe5a1e2e8d5236020f33ffb2294"), + Timeout: 120, + Confirmation: 5, + }, } // MainnetTrustedCheckpoint contains the light client trusted checkpoint for the main network. @@ -121,6 +126,11 @@ var ( new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e5)), }, }, + Recovery: &RecoveryConfig{ + Contract: common.HexToAddress("0x4ebe3d13ab18b30d815711b7a33ef1226777b66d"), + Timeout: 120, + Confirmation: 5, + }, } // TaipeiChainConfig contains the chain parameters to run a node on the Taipei test network. @@ -158,6 +168,11 @@ var ( new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e5)), }, }, + Recovery: &RecoveryConfig{ + Contract: common.HexToAddress("0xac86ab80ab27007801f36f6622fbe0a9432291a2"), + Timeout: 120, + Confirmation: 1, + }, } // TestnetTrustedCheckpoint contains the light client trusted checkpoint for the Ropsten test network. @@ -203,6 +218,11 @@ var ( new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e5)), }, }, + Recovery: &RecoveryConfig{ + Contract: common.HexToAddress("0x3828134ba7a0629fd52067b80fe696f400eb83dc"), + Timeout: 120, + Confirmation: 1, + }, } // AllEthashProtocolChanges contains every protocol change (EIPs) introduced @@ -210,18 +230,18 @@ var ( // // This configuration is intentionally not using keyed fields to force anyone // adding flags to the config to also have to set these fields. - AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), 0, big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, nil} + AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), 0, big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, nil, nil} // AllCliqueProtocolChanges contains every protocol change (EIPs) introduced // and accepted by the Ethereum core developers into the Clique consensus. // // This configuration is intentionally not using keyed fields to force anyone // adding flags to the config to also have to set these fields. - AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), 0, big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil} + AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), 0, big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil, nil} - AllDexconProtocolChanges = &ChainConfig{big.NewInt(1337), 0, big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, new(DexconConfig)} + AllDexconProtocolChanges = &ChainConfig{big.NewInt(1337), 0, big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, new(DexconConfig), new(RecoveryConfig)} - TestChainConfig = &ChainConfig{big.NewInt(1), 0, big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, nil} + TestChainConfig = &ChainConfig{big.NewInt(1), 0, big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, nil, nil} TestRules = TestChainConfig.Rules(new(big.Int)) // Ethereum MainnetChainConfig is the chain parameters to run a node on the main network. @@ -299,6 +319,9 @@ type ChainConfig struct { Ethash *EthashConfig `json:"ethash,omitempty"` Clique *CliqueConfig `json:"clique,omitempty"` Dexcon *DexconConfig `json:"dexcon,omitempty"` + + // Dexcon Recovery + Recovery *RecoveryConfig `json:"recovery,omitempty"` } // EthashConfig is the consensus engine configs for proof-of-work based sealing. @@ -372,6 +395,12 @@ func (d *DexconConfig) String() string { ) } +type RecoveryConfig struct { + Contract common.Address `json:"contract"` + Timeout int `json:"timeout"` + Confirmation int `json:"confirmation"` +} + // String implements the fmt.Stringer interface. func (c *ChainConfig) String() string { var engine interface{} diff --git a/params/gen_dexcon_config.go b/params/gen_dexcon_config.go index 1afe11f56..38753916a 100644 --- a/params/gen_dexcon_config.go +++ b/params/gen_dexcon_config.go @@ -22,6 +22,7 @@ func (d DexconConfig) MarshalJSON() ([]byte, error) { MiningVelocity float32 `json:"miningVelocity"` NextHalvingSupply *math.HexOrDecimal256 `json:"nextHalvingSupply"` LastHalvedAmount *math.HexOrDecimal256 `json:"lastHalvedAmount"` + MinGasPrice *math.HexOrDecimal256 `json:"minGasPrice"` BlockGasLimit uint64 `json:"blockGasLimit"` LambdaBA uint64 `json:"lambdaBA"` LambdaDKG uint64 `json:"lambdaDKG"` @@ -30,7 +31,6 @@ func (d DexconConfig) MarshalJSON() ([]byte, error) { RoundLength uint64 `json:"roundLength"` MinBlockInterval uint64 `json:"minBlockInterval"` FineValues []*math.HexOrDecimal256 `json:"fineValues"` - MinGasPrice *math.HexOrDecimal256 `json:"minGasPrice"` } var enc DexconConfig enc.GenesisCRSText = d.GenesisCRSText @@ -40,6 +40,7 @@ func (d DexconConfig) MarshalJSON() ([]byte, error) { enc.MiningVelocity = d.MiningVelocity enc.NextHalvingSupply = (*math.HexOrDecimal256)(d.NextHalvingSupply) enc.LastHalvedAmount = (*math.HexOrDecimal256)(d.LastHalvedAmount) + enc.MinGasPrice = (*math.HexOrDecimal256)(d.MinGasPrice) enc.BlockGasLimit = d.BlockGasLimit enc.LambdaBA = d.LambdaBA enc.LambdaDKG = d.LambdaDKG @@ -53,7 +54,6 @@ func (d DexconConfig) MarshalJSON() ([]byte, error) { enc.FineValues[k] = (*math.HexOrDecimal256)(v) } } - enc.MinGasPrice = (*math.HexOrDecimal256)(d.MinGasPrice) return json.Marshal(&enc) } @@ -67,6 +67,7 @@ func (d *DexconConfig) UnmarshalJSON(input []byte) error { MiningVelocity *float32 `json:"miningVelocity"` NextHalvingSupply *math.HexOrDecimal256 `json:"nextHalvingSupply"` LastHalvedAmount *math.HexOrDecimal256 `json:"lastHalvedAmount"` + MinGasPrice *math.HexOrDecimal256 `json:"minGasPrice"` BlockGasLimit *uint64 `json:"blockGasLimit"` LambdaBA *uint64 `json:"lambdaBA"` LambdaDKG *uint64 `json:"lambdaDKG"` @@ -75,7 +76,6 @@ func (d *DexconConfig) UnmarshalJSON(input []byte) error { RoundLength *uint64 `json:"roundLength"` MinBlockInterval *uint64 `json:"minBlockInterval"` FineValues []*math.HexOrDecimal256 `json:"fineValues"` - MinGasPrice *math.HexOrDecimal256 `json:"minGasPrice"` } var dec DexconConfig if err := json.Unmarshal(input, &dec); err != nil { @@ -102,6 +102,9 @@ func (d *DexconConfig) UnmarshalJSON(input []byte) error { if dec.LastHalvedAmount != nil { d.LastHalvedAmount = (*big.Int)(dec.LastHalvedAmount) } + if dec.MinGasPrice != nil { + d.MinGasPrice = (*big.Int)(dec.MinGasPrice) + } if dec.BlockGasLimit != nil { d.BlockGasLimit = *dec.BlockGasLimit } @@ -129,8 +132,5 @@ func (d *DexconConfig) UnmarshalJSON(input []byte) error { d.FineValues[k] = (*big.Int)(v) } } - if dec.MinGasPrice != nil { - d.MinGasPrice = (*big.Int)(dec.MinGasPrice) - } return nil } -- cgit v1.2.3