aboutsummaryrefslogtreecommitdiffstats
path: root/dex
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-04-01 18:01:26 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-15 22:09:55 +0800
commitbde4a6cc02c6806093d2a49a86463f81358ca3d8 (patch)
treebc3d617f8ff755f6cca5c4fc1dff7b5457845c9f /dex
parent3c0372165e723de9f1bd3ea8dacd579810463f6d (diff)
downloadgo-tangerine-bde4a6cc02c6806093d2a49a86463f81358ca3d8.tar
go-tangerine-bde4a6cc02c6806093d2a49a86463f81358ca3d8.tar.gz
go-tangerine-bde4a6cc02c6806093d2a49a86463f81358ca3d8.tar.bz2
go-tangerine-bde4a6cc02c6806093d2a49a86463f81358ca3d8.tar.lz
go-tangerine-bde4a6cc02c6806093d2a49a86463f81358ca3d8.tar.xz
go-tangerine-bde4a6cc02c6806093d2a49a86463f81358ca3d8.tar.zst
go-tangerine-bde4a6cc02c6806093d2a49a86463f81358ca3d8.zip
vendor: sync to latest core (#320)
* vendor: sync to latest core * dex, core: fix conflict x
Diffstat (limited to 'dex')
-rw-r--r--dex/app.go26
-rw-r--r--dex/app_test.go18
-rw-r--r--dex/blockproposer.go12
-rw-r--r--dex/cache.go1
-rw-r--r--dex/cache_test.go42
-rw-r--r--dex/handler.go5
-rw-r--r--dex/protocol_test.go12
7 files changed, 47 insertions, 69 deletions
diff --git a/dex/app.go b/dex/app.go
index 9a72d7795..5a268a09d 100644
--- a/dex/app.go
+++ b/dex/app.go
@@ -162,9 +162,9 @@ func (d *DexconApp) preparePayload(ctx context.Context, position coreTypes.Posit
default:
}
- // deliver height = position height + 1
- if d.deliveredHeight+d.undeliveredNum != position.Height {
- return nil, fmt.Errorf("expected height %d but get %d", d.deliveredHeight+d.undeliveredNum, position.Height)
+ // deliver height + 1 = position height
+ if d.deliveredHeight+d.undeliveredNum+1 != position.Height {
+ return nil, fmt.Errorf("expected height %d but get %d", d.deliveredHeight+d.undeliveredNum+1, position.Height)
}
deliveredBlock := d.blockchain.GetBlockByNumber(d.deliveredHeight)
@@ -308,8 +308,8 @@ func (d *DexconApp) VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifySta
d.appMu.RLock()
defer d.appMu.RUnlock()
- // deliver height = position height + 1
- if d.deliveredHeight+d.undeliveredNum != block.Position.Height {
+ // deliver height + 1 = position height
+ if d.deliveredHeight+d.undeliveredNum+1 != block.Position.Height {
return coreTypes.VerifyRetryLater
}
@@ -414,10 +414,10 @@ func (d *DexconApp) VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifySta
func (d *DexconApp) BlockDelivered(
blockHash coreCommon.Hash,
blockPosition coreTypes.Position,
- result coreTypes.FinalizationResult) {
+ rand []byte) {
- log.Debug("DexconApp block deliver", "height", result.Height, "hash", blockHash, "position", blockPosition.String())
- defer log.Debug("DexconApp block delivered", "height", result.Height, "hash", blockHash, "position", blockPosition.String())
+ log.Debug("DexconApp block deliver", "hash", blockHash, "position", blockPosition.String())
+ defer log.Debug("DexconApp block delivered", "hash", blockHash, "position", blockPosition.String())
d.appMu.Lock()
defer d.appMu.Unlock()
@@ -428,7 +428,7 @@ func (d *DexconApp) BlockDelivered(
}
block.Payload = nil
- block.Finalization = result
+ block.Randomness = rand
dexconMeta, err := rlp.EncodeToBytes(block)
if err != nil {
panic(err)
@@ -445,14 +445,14 @@ func (d *DexconApp) BlockDelivered(
}
newBlock := types.NewBlock(&types.Header{
- Number: new(big.Int).SetUint64(result.Height),
- Time: big.NewInt(result.Timestamp.UnixNano() / 1000000),
+ Number: new(big.Int).SetUint64(block.Position.Height),
+ Time: uint64(block.Timestamp.UnixNano() / 1000000),
Coinbase: owner,
GasLimit: d.gov.DexconConfiguration(block.Position.Round).BlockGasLimit,
Difficulty: big.NewInt(1),
Round: block.Position.Round,
DexconMeta: dexconMeta,
- Randomness: result.Randomness,
+ Randomness: block.Randomness,
}, txs, nil, nil)
if block.IsEmpty() {
@@ -470,7 +470,7 @@ func (d *DexconApp) BlockDelivered(
}
d.removeConfirmedBlock(blockHash)
- d.deliveredHeight = result.Height
+ d.deliveredHeight = block.Position.Height
// New blocks are finalized, notify other components.
go d.finalizedBlockFeed.Send(core.NewFinalizedBlockEvent{Block: d.blockchain.CurrentBlock()})
diff --git a/dex/app_test.go b/dex/app_test.go
index e648abdbd..652aaa0b2 100644
--- a/dex/app_test.go
+++ b/dex/app_test.go
@@ -39,7 +39,7 @@ type App interface {
PrepareWitness(height uint64) (witness coreTypes.Witness, err error)
VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifyStatus
BlockConfirmed(block coreTypes.Block)
- BlockDelivered(blockHash coreCommon.Hash, position coreTypes.Position, result coreTypes.FinalizationResult)
+ BlockDelivered(blockHash coreCommon.Hash, position coreTypes.Position, rand []byte)
SubscribeNewFinalizedBlockEvent(ch chan<- core.NewFinalizedBlockEvent) event.Subscription
Stop()
}
@@ -268,7 +268,7 @@ func (f *ConfigFactory) Run() {
go f.center.DeliverProduct(makerName(f.name),
&PositionProduct{position: coreTypes.Position{
Round: 0,
- Height: 0,
+ Height: coreTypes.GenesisHeight,
}})
f.initialized = true
@@ -1634,15 +1634,11 @@ func (f *BlockConfirmedFactory) Run() {
block := f.convertProduct(product)
block.ProposerID = coreTypes.NewNodeID(f.masterKey.PublicKey())
+ block.Timestamp = time.Now()
f.stopTimeMu.RLock()
f.App.BlockConfirmed(block)
f.stopTimeMu.RUnlock()
- block.Finalization = coreTypes.FinalizationResult{
- Timestamp: time.Now(),
- Height: block.Position.Height + 1,
- }
-
f.center.DeliverProduct(makerName(f.name), &BlockConfirmedProduct{
block: block,
})
@@ -1916,7 +1912,7 @@ func (f *BlockDeliveredFactory) Run() {
block := f.convertProduct(product)
f.stopTimeMu.RLock()
- f.App.BlockDelivered(block.Hash, block.Position, block.Finalization)
+ f.App.BlockDelivered(block.Hash, block.Position, block.Randomness)
f.stopTimeMu.RUnlock()
}
}
@@ -1987,7 +1983,7 @@ func (t *bdBlockHashTester) ViewAndRecord(product Product) {
func (t bdBlockHashTester) InputsForTest(product Product) []reflect.Value {
block := product.(*BlockConfirmedProduct).block
return []reflect.Value{reflect.ValueOf(coreCommon.Hash{}), reflect.ValueOf(block.Position),
- reflect.ValueOf(block.Finalization)}
+ reflect.ValueOf(block.Randomness)}
}
func (t *bdBlockHashTester) ValidateResults(results []reflect.Value) error {
@@ -2042,7 +2038,7 @@ func (t *bdBlockDeliveredTester) ViewAndRecord(product Product) {
case *BlockConfirmedProduct:
app := t.App.(*DexconApp)
block := product.(*BlockConfirmedProduct).block
- t.expectHeight = block.Position.Height + 1
+ t.expectHeight = block.Position.Height
var txs []*types.Transaction
_, txs = app.getConfirmedBlockByHash(block.Hash)
@@ -2079,7 +2075,7 @@ func (t *bdBlockDeliveredTester) ViewAndRecord(product Product) {
func (t bdBlockDeliveredTester) InputsForTest(product Product) []reflect.Value {
block := product.(*BlockConfirmedProduct).block
return []reflect.Value{reflect.ValueOf(block.Hash), reflect.ValueOf(block.Position),
- reflect.ValueOf(block.Finalization)}
+ reflect.ValueOf(block.Randomness)}
}
func (t *bdBlockDeliveredTester) ValidateResults(results []reflect.Value) error {
diff --git a/dex/blockproposer.go b/dex/blockproposer.go
index 846e65617..c035eda7c 100644
--- a/dex/blockproposer.go
+++ b/dex/blockproposer.go
@@ -172,13 +172,13 @@ Loop:
b.watchCat.Feed(blocks[len(blocks)-1].Position)
log.Debug("Filling compaction chain", "num", len(blocks),
- "first", blocks[0].Finalization.Height,
- "last", blocks[len(blocks)-1].Finalization.Height)
+ "first", blocks[0].Position.Height,
+ "last", blocks[len(blocks)-1].Position.Height)
if _, err := consensusSync.SyncBlocks(blocks, false); err != nil {
log.Debug("SyncBlocks fail", "err", err)
return nil, err
}
- coreHeight = blocks[len(blocks)-1].Finalization.Height
+ coreHeight = blocks[len(blocks)-1].Position.Height
select {
case <-b.stopCh:
@@ -203,8 +203,8 @@ ListenLoop:
if len(blocks) > 0 {
b.watchCat.Feed(blocks[len(blocks)-1].Position)
log.Debug("Filling compaction chain", "num", len(blocks),
- "first", blocks[0].Finalization.Height,
- "last", blocks[len(blocks)-1].Finalization.Height)
+ "first", blocks[0].Position.Height,
+ "last", blocks[len(blocks)-1].Position.Height)
synced, err := consensusSync.SyncBlocks(blocks, true)
if err != nil {
log.Error("SyncBlocks fail", "err", err)
@@ -215,7 +215,7 @@ ListenLoop:
log.Debug("Consensus core synced")
break ListenLoop
}
- coreHeight = blocks[len(blocks)-1].Finalization.Height
+ coreHeight = blocks[len(blocks)-1].Position.Height
}
case <-sub.Err():
log.Debug("System stopped when syncing consensus core")
diff --git a/dex/cache.go b/dex/cache.go
index 04030eaaf..951657fae 100644
--- a/dex/cache.go
+++ b/dex/cache.go
@@ -99,7 +99,6 @@ func (c *cache) addBlock(block *coreTypes.Block) {
c.lock.Lock()
defer c.lock.Unlock()
block = block.Clone()
- block.Finalization.Height = 0
if len(c.blockCache) >= c.size {
// Randomly delete one entry.
for k := range c.blockCache {
diff --git a/dex/cache_test.go b/dex/cache_test.go
index 22b1b9b26..b06effafb 100644
--- a/dex/cache_test.go
+++ b/dex/cache_test.go
@@ -216,37 +216,29 @@ func TestCacheFinalizedBlock(t *testing.T) {
Position: coreTypes.Position{
Height: 1,
},
- Hash: coreCommon.NewRandomHash(),
- Finalization: coreTypes.FinalizationResult{
- Randomness: randomBytes(),
- },
+ Hash: coreCommon.NewRandomHash(),
+ Randomness: randomBytes(),
}
block2 := &coreTypes.Block{
Position: coreTypes.Position{
Height: 2,
},
- Hash: coreCommon.NewRandomHash(),
- Finalization: coreTypes.FinalizationResult{
- Randomness: randomBytes(),
- },
+ Hash: coreCommon.NewRandomHash(),
+ Randomness: randomBytes(),
}
block3 := &coreTypes.Block{
Position: coreTypes.Position{
Height: 3,
},
- Hash: coreCommon.NewRandomHash(),
- Finalization: coreTypes.FinalizationResult{
- Randomness: randomBytes(),
- },
+ Hash: coreCommon.NewRandomHash(),
+ Randomness: randomBytes(),
}
block4 := &coreTypes.Block{
Position: coreTypes.Position{
Height: 4,
},
- Hash: coreCommon.NewRandomHash(),
- Finalization: coreTypes.FinalizationResult{
- Randomness: randomBytes(),
- },
+ Hash: coreCommon.NewRandomHash(),
+ Randomness: randomBytes(),
}
cache.addFinalizedBlock(block1)
cache.addFinalizedBlock(block2)
@@ -291,18 +283,18 @@ func TestCacheFinalizedBlock(t *testing.T) {
}
}
finalizedBlock5 := block5.Clone()
- finalizedBlock5.Finalization.Randomness = randomBytes()
+ finalizedBlock5.Randomness = randomBytes()
cache.addFinalizedBlock(finalizedBlock5)
block = cache.finalizedBlock(block5.Position)
if block == nil {
t.Errorf("expecting block %s in cache", finalizedBlock5)
}
if !reflect.DeepEqual(
- block.Finalization.Randomness,
- finalizedBlock5.Finalization.Randomness) {
+ block.Randomness,
+ finalizedBlock5.Randomness) {
t.Errorf("mismatch randomness, have %s, want %s",
- block.Finalization.Randomness,
- finalizedBlock5.Finalization.Randomness)
+ block.Randomness,
+ finalizedBlock5.Randomness)
}
blocks = cache.blocks(coreCommon.Hashes{block5.Hash})
if len(blocks) != 1 {
@@ -312,11 +304,11 @@ func TestCacheFinalizedBlock(t *testing.T) {
t.Errorf("get wrong block: have %s, want %s", blocks[0], block5)
}
if !reflect.DeepEqual(
- blocks[0].Finalization.Randomness,
- finalizedBlock5.Finalization.Randomness) {
+ blocks[0].Randomness,
+ finalizedBlock5.Randomness) {
t.Errorf("mismatch randomness, have %s, want %s",
- blocks[0].Finalization.Randomness,
- finalizedBlock5.Finalization.Randomness)
+ blocks[0].Randomness,
+ finalizedBlock5.Randomness)
}
}
}
diff --git a/dex/handler.go b/dex/handler.go
index 6395c4113..61e382610 100644
--- a/dex/handler.go
+++ b/dex/handler.go
@@ -1083,7 +1083,7 @@ func (pm *ProtocolManager) BroadcastRecords(records []*enr.Record) {
// BroadcastFinalizedBlock broadcasts the finalized core block to some of its peers.
func (pm *ProtocolManager) BroadcastFinalizedBlock(block *coreTypes.Block) {
- if len(block.Finalization.Randomness) == 0 {
+ if len(block.Randomness) == 0 {
log.Warn("Ignore broadcast finalized block without randomness", "block", block)
return
}
@@ -1132,8 +1132,7 @@ func (pm *ProtocolManager) BroadcastAgreementResult(
agreement *coreTypes.AgreementResult) {
block := pm.cache.blocks(coreCommon.Hashes{agreement.BlockHash})
if len(block) != 0 {
- block[0].Finalization.Height = agreement.FinalizationHeight
- block[0].Finalization.Randomness = agreement.Randomness
+ block[0].Randomness = agreement.Randomness
pm.cache.addFinalizedBlock(block[0])
}
diff --git a/dex/protocol_test.go b/dex/protocol_test.go
index 7e0e1a9a4..d6bebc18a 100644
--- a/dex/protocol_test.go
+++ b/dex/protocol_test.go
@@ -334,11 +334,7 @@ func TestRecvCoreBlocks(t *testing.T) {
Height: 13,
Data: []byte{4, 4, 4, 4, 4},
},
- Finalization: coreTypes.FinalizationResult{
- Randomness: []byte{5, 5, 5, 5, 5},
- Timestamp: time.Now().UTC(),
- Height: 13,
- },
+ Randomness: []byte{5, 5, 5, 5, 5},
Signature: coreCrypto.Signature{
Type: "signature",
Signature: []byte("signature"),
@@ -387,11 +383,7 @@ func TestSendCoreBlocks(t *testing.T) {
Height: 13,
Data: []byte{4, 4, 4, 4, 4},
},
- Finalization: coreTypes.FinalizationResult{
- Randomness: []byte{5, 5, 5, 5, 5},
- Timestamp: time.Now().UTC(),
- Height: 13,
- },
+ Randomness: []byte{5, 5, 5, 5, 5},
Signature: coreCrypto.Signature{
Type: "signature",
Signature: []byte("signature"),