aboutsummaryrefslogtreecommitdiffstats
path: root/dex
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-01-06 23:21:54 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:21 +0800
commitc6c8b6cfd083058a255d614db14df0e75fdd3482 (patch)
tree23fd25eec0a08923f2516fc688ad2487592ae928 /dex
parent2b7671af8b76f64bcbe69d99509d454cb33be5ad (diff)
downloadgo-tangerine-c6c8b6cfd083058a255d614db14df0e75fdd3482.tar.gz
go-tangerine-c6c8b6cfd083058a255d614db14df0e75fdd3482.tar.zst
go-tangerine-c6c8b6cfd083058a255d614db14df0e75fdd3482.zip
core: vm: implement byzantine reporting mechanism (#128)
Diffstat (limited to 'dex')
-rw-r--r--dex/app_test.go15
-rw-r--r--dex/governance.go66
2 files changed, 66 insertions, 15 deletions
diff --git a/dex/app_test.go b/dex/app_test.go
index 9278160fb..7fc4933de 100644
--- a/dex/app_test.go
+++ b/dex/app_test.go
@@ -494,12 +494,18 @@ func BenchmarkBlockDeliveredFlow(b *testing.B) {
func newTestDexonWithGenesis(allocKey *ecdsa.PrivateKey) (*Dexon, error) {
db := ethdb.NewMemDatabase()
+ key, err := crypto.GenerateKey()
+ if err != nil {
+ panic(err)
+ }
+
testBankAddress := crypto.PubkeyToAddress(allocKey.PublicKey)
genesis := core.DefaultTestnetGenesisBlock()
genesis.Alloc = core.GenesisAlloc{
testBankAddress: {
- Balance: big.NewInt(100000000000000000),
- Staked: big.NewInt(50000000000000000),
+ Balance: big.NewInt(100000000000000000),
+ Staked: big.NewInt(50000000000000000),
+ PublicKey: crypto.FromECDSAPub(&key.PublicKey),
},
}
chainConfig, _, err := core.SetupGenesisBlock(db, genesis)
@@ -507,11 +513,6 @@ func newTestDexonWithGenesis(allocKey *ecdsa.PrivateKey) (*Dexon, error) {
return nil, err
}
- key, err := crypto.GenerateKey()
- if err != nil {
- return nil, err
- }
-
config := Config{PrivateKey: key}
vmConfig := vm.Config{IsBlockProposer: true}
diff --git a/dex/governance.go b/dex/governance.go
index 199bcdc87..ec029f2f1 100644
--- a/dex/governance.go
+++ b/dex/governance.go
@@ -259,6 +259,64 @@ func (d *DexconGovernance) AddDKGFinalize(round uint64, final *dkgTypes.Finalize
}
}
+// ReportForkVote reports a node for forking votes.
+func (d *DexconGovernance) ReportForkVote(vote1, vote2 *coreTypes.Vote) {
+ method := vm.GovernanceContractName2Method["report"]
+
+ vote1Bytes, err := rlp.EncodeToBytes(vote1)
+ if err != nil {
+ log.Error("failed to RLP encode vote1 to bytes", "err", err)
+ return
+ }
+
+ vote2Bytes, err := rlp.EncodeToBytes(vote2)
+ if err != nil {
+ log.Error("failed to RLP encode vote2 to bytes", "err", err)
+ return
+ }
+
+ res, err := method.Inputs.Pack(big.NewInt(vm.ReportTypeForkVote), vote1Bytes, vote2Bytes)
+ if err != nil {
+ log.Error("failed to pack report input", "err", err)
+ return
+ }
+
+ data := append(method.Id(), res...)
+ err = d.sendGovTx(context.Background(), data)
+ if err != nil {
+ log.Error("failed to send report fork vote tx", "err", err)
+ }
+}
+
+// ReportForkBlock reports a node for forking blocks.
+func (d *DexconGovernance) ReportForkBlock(block1, block2 *coreTypes.Block) {
+ method := vm.GovernanceContractName2Method["report"]
+
+ block1Bytes, err := rlp.EncodeToBytes(block1)
+ if err != nil {
+ log.Error("failed to RLP encode block1 to bytes", "err", err)
+ return
+ }
+
+ block2Bytes, err := rlp.EncodeToBytes(block2)
+ if err != nil {
+ log.Error("failed to RLP encode block2 to bytes", "err", err)
+ return
+ }
+
+ res, err := method.Inputs.Pack(big.NewInt(vm.ReportTypeForkBlock), block1Bytes, block2Bytes)
+ if err != nil {
+ log.Error("failed to pack report input", "err", err)
+ return
+ }
+
+ data := append(method.Id(), res...)
+ err = d.sendGovTx(context.Background(), data)
+ if err != nil {
+ log.Error("failed to send report fork block tx", "err", err)
+ }
+}
+
func (d *DexconGovernance) GetNumChains(round uint64) uint32 {
return d.Configuration(round).NumChains
}
@@ -292,11 +350,3 @@ func (d *DexconGovernance) DKGSet(round uint64) (map[string]struct{}, error) {
}
return r, nil
}
-
-func (d *DexconGovernance) ReportForkVote(vote1, vote2 *coreTypes.Vote) {
- // TODO: finish this.
-}
-
-func (d *DexconGovernance) ReportForkBlock(block1, block2 *coreTypes.Block) {
- // TODO: finish this.
-}