aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2018-12-19 10:22:38 +0800
committerWei-Ning Huang <w@dexon.org>2018-12-19 20:54:27 +0800
commit24d6c68a85db33930c7cdba7ad67f0512028619c (patch)
treef6cfb67c2d096468a8b18089ca49f21fee0ee893
parente677874800085b8b9a4d102d41d4b1218029308f (diff)
downloaddexon-24d6c68a85db33930c7cdba7ad67f0512028619c.tar.gz
dexon-24d6c68a85db33930c7cdba7ad67f0512028619c.tar.zst
dexon-24d6c68a85db33930c7cdba7ad67f0512028619c.zip
dex: remove duplicate declaration of WitnessData (#92)
Remove duplicate declaration of WitnessData and remove the TxHash field in witness data since it does not need to be witnessed.
-rw-r--r--core/blockchain_test.go6
-rw-r--r--core/types/block.go1
-rw-r--r--dex/app.go11
-rw-r--r--dex/app_test.go6
4 files changed, 3 insertions, 21 deletions
diff --git a/core/blockchain_test.go b/core/blockchain_test.go
index 8251df6dd..ae4747116 100644
--- a/core/blockchain_test.go
+++ b/core/blockchain_test.go
@@ -1452,7 +1452,6 @@ func TestProcessPendingBlock(t *testing.T) {
if i == 0 {
witnessData := types.WitnessData{
Root: gspec.ToBlock(nil).Root(),
- TxHash: gspec.ToBlock(nil).TxHash(),
ReceiptHash: gspec.ToBlock(nil).ReceiptHash(),
}
witnessDataBytes, err = rlp.EncodeToBytes(&witnessData)
@@ -1462,7 +1461,6 @@ func TestProcessPendingBlock(t *testing.T) {
} else {
witnessData := types.WitnessData{
Root: chain.pendingBlocks[uint64(i)].block.Root(),
- TxHash: chain.pendingBlocks[uint64(i)].block.TxHash(),
ReceiptHash: chain.pendingBlocks[uint64(i)].block.ReceiptHash(),
}
witnessDataBytes, err = rlp.EncodeToBytes(&witnessData)
@@ -1515,7 +1513,6 @@ func TestProcessPendingBlock(t *testing.T) {
// Validate witness fail with unknown block.
witnessData := types.WitnessData{
Root: chain.pendingBlocks[processNum].block.Root(),
- TxHash: chain.pendingBlocks[processNum].block.TxHash(),
ReceiptHash: chain.pendingBlocks[processNum].block.ReceiptHash(),
}
witnessDataBytes, err := rlp.EncodeToBytes(&witnessData)
@@ -1539,7 +1536,6 @@ func TestProcessPendingBlock(t *testing.T) {
// Validate witness fail with unexpected root.
witnessData = types.WitnessData{
Root: chain.pendingBlocks[processNum].block.Root(),
- TxHash: chain.pendingBlocks[processNum].block.TxHash(),
ReceiptHash: chain.pendingBlocks[processNum].block.ReceiptHash(),
}
witnessDataBytes, err = rlp.EncodeToBytes(&witnessData)
@@ -1563,7 +1559,6 @@ func TestProcessPendingBlock(t *testing.T) {
// Apply transaction fail with insufficient fund.
witnessData = types.WitnessData{
Root: chain.pendingBlocks[processNum].block.Root(),
- TxHash: chain.pendingBlocks[processNum].block.TxHash(),
ReceiptHash: chain.pendingBlocks[processNum].block.ReceiptHash(),
}
witnessDataBytes, err = rlp.EncodeToBytes(&witnessData)
@@ -1596,7 +1591,6 @@ func TestProcessPendingBlock(t *testing.T) {
// Apply transaction fail with nonce too height.
witnessData = types.WitnessData{
Root: chain.pendingBlocks[processNum].block.Root(),
- TxHash: chain.pendingBlocks[processNum].block.TxHash(),
ReceiptHash: chain.pendingBlocks[processNum].block.ReceiptHash(),
}
witnessDataBytes, err = rlp.EncodeToBytes(&witnessData)
diff --git a/core/types/block.go b/core/types/block.go
index fb61cadfc..9fe68e362 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -67,7 +67,6 @@ func (n *BlockNonce) UnmarshalText(input []byte) error {
// WitnessData represents the witness data.
type WitnessData struct {
Root common.Hash
- TxHash common.Hash
ReceiptHash common.Hash
}
diff --git a/dex/app.go b/dex/app.go
index 8da00d07b..9dcfd87e9 100644
--- a/dex/app.go
+++ b/dex/app.go
@@ -50,12 +50,6 @@ type DexconApp struct {
chainLocks sync.Map
}
-type witnessData struct {
- Root common.Hash
- TxHash common.Hash
- ReceiptHash common.Hash
-}
-
func NewDexconApp(txPool *core.TxPool, blockchain *core.BlockChain, gov *DexconGovernance,
chainDB ethdb.Database, config *Config) *DexconApp {
return &DexconApp{
@@ -283,9 +277,8 @@ func (d *DexconApp) PrepareWitness(consensusHeight uint64) (witness coreTypes.Wi
return witness, fmt.Errorf("last pending height < consensus height")
}
- witnessData, err := rlp.EncodeToBytes(&witnessData{
+ witnessData, err := rlp.EncodeToBytes(&types.WitnessData{
Root: witnessBlock.Root(),
- TxHash: witnessBlock.TxHash(),
ReceiptHash: witnessBlock.ReceiptHash(),
})
if err != nil {
@@ -300,7 +293,7 @@ func (d *DexconApp) PrepareWitness(consensusHeight uint64) (witness coreTypes.Wi
// VerifyBlock verifies if the payloads are valid.
func (d *DexconApp) VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifyStatus {
- var witnessData witnessData
+ var witnessData types.WitnessData
err := rlp.DecodeBytes(block.Witness.Data, &witnessData)
if err != nil {
log.Error("failed to RLP decode witness data", "error", err)
diff --git a/dex/app_test.go b/dex/app_test.go
index abe83b92a..82bf8a6f6 100644
--- a/dex/app_test.go
+++ b/dex/app_test.go
@@ -115,16 +115,12 @@ func TestPrepareWitness(t *testing.T) {
t.Errorf("unexpeted witness height %v", witness.Height)
}
- var witnessData witnessData
+ var witnessData types.WitnessData
err = rlp.DecodeBytes(witness.Data, &witnessData)
if err != nil {
t.Errorf("rlp decode error: %v", err)
}
- if witnessData.TxHash != currentBlock.TxHash() {
- t.Errorf("expect tx hash %v but %v", currentBlock.TxHash(), witnessData.TxHash)
- }
-
if witnessData.Root != currentBlock.Root() {
t.Errorf("expect root %v but %v", currentBlock.Root(), witnessData.Root)
}