aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei-Ning Huang <w@cobinhood.com>2018-10-16 19:26:29 +0800
committerWei-Ning Huang <w@dexon.org>2019-03-12 12:19:09 +0800
commit88b272df86618979916a2b9f45723745dd556245 (patch)
tree7e33b4753e3920e65361991d695aeb1cadba92d1
parent0c555d3f347dc8458ddae614b093c9b11d54e629 (diff)
downloaddexon-88b272df86618979916a2b9f45723745dd556245.tar.gz
dexon-88b272df86618979916a2b9f45723745dd556245.tar.zst
dexon-88b272df86618979916a2b9f45723745dd556245.zip
dex/core: misc bug fixes
-rw-r--r--consensus/dexcon/dexcon.go13
-rw-r--r--core/types/block.go3
-rw-r--r--core/vm/governance.go2
-rw-r--r--dex/api_backend.go3
-rw-r--r--dex/app.go5
-rw-r--r--dex/governance.go4
-rw-r--r--params/config.go3
-rw-r--r--test/genesis.json2
-rwxr-xr-xtest/run_test.sh2
9 files changed, 27 insertions, 10 deletions
diff --git a/consensus/dexcon/dexcon.go b/consensus/dexcon/dexcon.go
index c18e3cc6a..4017637b0 100644
--- a/consensus/dexcon/dexcon.go
+++ b/consensus/dexcon/dexcon.go
@@ -59,7 +59,13 @@ func (d *Dexcon) VerifyHeader(chain consensus.ChainReader, header *types.Header,
// method returns a quit channel to abort the operations and a results channel to
// retrieve the async verifications (the order is that of the input slice).
func (d *Dexcon) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error) {
- return make(chan struct{}), make(chan error)
+ abort, results := make(chan struct{}), make(chan error)
+ go func() {
+ for range headers {
+ results <- nil
+ }
+ }()
+ return abort, results
}
// verifyHeader checks whether a header conforms to the consensus rules.The
@@ -99,9 +105,10 @@ func (d *Dexcon) Prepare(chain consensus.ChainReader, header *types.Header) erro
// Finalize implements consensus.Engine, ensuring no uncles are set, nor block
// rewards given, and returns the final block.
func (d *Dexcon) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
- reward := new(big.Int).Div(d.config.BlockReward, new(big.Int).SetUint64(uint64(d.config.NumChains)))
+ blockReward := big.NewInt(100000000000)
+ reward := new(big.Int).Div(blockReward, new(big.Int).SetUint64(uint64(d.config.NumChains)))
state.AddBalance(header.Coinbase, reward)
- header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
+ header.Root = state.IntermediateRoot(true)
return types.NewBlock(header, txs, uncles, receipts), nil
}
diff --git a/core/types/block.go b/core/types/block.go
index 1d403d972..3d0997f5e 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -300,7 +300,8 @@ func (b *Block) ReceiptHash() common.Hash { return b.header.ReceiptHash }
func (b *Block) UncleHash() common.Hash { return b.header.UncleHash }
func (b *Block) Extra() []byte { return common.CopyBytes(b.header.Extra) }
-func (b *Block) Header() *Header { return CopyHeader(b.header) }
+func (b *Block) Header() *Header { return CopyHeader(b.header) }
+func (b *Block) RawHeader() *Header { return b.header }
// Body returns the non-header content of the block.
func (b *Block) Body() *Body { return &Body{b.transactions, b.uncles} }
diff --git a/core/vm/governance.go b/core/vm/governance.go
index c9ab74bd7..9b4e2dde6 100644
--- a/core/vm/governance.go
+++ b/core/vm/governance.go
@@ -1540,7 +1540,7 @@ func (g *GovernanceContract) proposeCRS(signedCRS []byte) ([]byte, error) {
dkgComplaints = append(dkgComplaints, x)
}
- threshold := int(g.state.DKGSetSize().Uint64() / 3 + 1)
+ threshold := int(g.state.DKGSetSize().Uint64()/3 + 1)
dkgGPK, err := core.NewDKGGroupPublicKey(
round.Uint64(), dkgMasterPKs, dkgComplaints, threshold)
diff --git a/dex/api_backend.go b/dex/api_backend.go
index 9e9765d1a..411855bf3 100644
--- a/dex/api_backend.go
+++ b/dex/api_backend.go
@@ -79,6 +79,9 @@ func (b *DexAPIBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumb
}
func (b *DexAPIBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error) {
+ if blockNr == rpc.PendingBlockNumber {
+ blockNr = rpc.BlockNumber(b.dex.blockchain.CurrentBlock().Header().Number.Uint64())
+ }
header, err := b.HeaderByNumber(ctx, blockNr)
if header == nil || err != nil {
return nil, nil, err
diff --git a/dex/app.go b/dex/app.go
index 35a771460..85d7ea621 100644
--- a/dex/app.go
+++ b/dex/app.go
@@ -308,11 +308,12 @@ func (d *DexconApp) BlockDelivered(blockHash coreCommon.Hash, result coreTypes.F
_, err = d.blockchain.InsertChain(
[]*types.Block{types.NewBlock(&types.Header{
- ParentHash: common.Hash(block.ParentHash),
+ ParentHash: d.blockchain.CurrentBlock().Hash(),
Number: new(big.Int).SetUint64(result.Height),
- Time: new(big.Int).SetInt64(result.Timestamp.Unix()),
+ Time: big.NewInt(result.Timestamp.Unix()),
TxHash: types.DeriveSha(transactions),
Coinbase: common.BytesToAddress(block.ProposerID.Hash[:]),
+ GasLimit: 800000,
}, transactions, nil, nil)})
if err != nil {
log.Error("insert chain", "error", err)
diff --git a/dex/governance.go b/dex/governance.go
index a78cf2d4f..19b9e578c 100644
--- a/dex/governance.go
+++ b/dex/governance.go
@@ -109,6 +109,10 @@ func (d *DexconGovernance) sendGovTx(ctx context.Context, data []byte) error {
return err
}
+ if nonce > 0 {
+ nonce += 1
+ }
+
tx := types.NewTransaction(
nonce,
vm.GovernanceContractAddress,
diff --git a/params/config.go b/params/config.go
index ddcc054e9..1188fc987 100644
--- a/params/config.go
+++ b/params/config.go
@@ -235,7 +235,7 @@ type DexconConfig struct {
// String implements the stringer interface, returning the consensus engine details.
func (d *DexconConfig) String() string {
- return fmt.Sprintf("{GenesisCRSText: %v NumChains: %v LambdaBA: %v LambdaDKG: %v K: %v PhiRatio: %v NotarySetSize: %v DKGSetSize: %v RoundInterval: %v MinBlockInterval: %v MaxBlockInterval: %v",
+ return fmt.Sprintf("{GenesisCRSText: %v NumChains: %v LambdaBA: %v LambdaDKG: %v K: %v PhiRatio: %v NotarySetSize: %v DKGSetSize: %v RoundInterval: %v MinBlockInterval: %v MaxBlockInterval: %v BlockReward: %v",
d.GenesisCRSText,
d.NumChains,
d.LambdaBA,
@@ -247,6 +247,7 @@ func (d *DexconConfig) String() string {
d.RoundInterval,
d.MinBlockInterval,
d.MaxBlockInterval,
+ d.BlockReward,
)
}
diff --git a/test/genesis.json b/test/genesis.json
index 2963aaf3c..51857df5f 100644
--- a/test/genesis.json
+++ b/test/genesis.json
@@ -15,7 +15,7 @@
"phiRatio": 667000,
"notarySetSize": 4,
"dkgSetSize": 4,
- "roundInterval": 600000,
+ "roundInterval": 99999999999,
"minBlockInterval": 900,
"maxBlockInterval": 1100
}
diff --git a/test/run_test.sh b/test/run_test.sh
index df3505a00..b38ca4da6 100755
--- a/test/run_test.sh
+++ b/test/run_test.sh
@@ -11,7 +11,7 @@ for i in $(seq 0 3); do
rm -rf $datadir
$GETH --datadir=$datadir init genesis.json
cp test$i.nodekey $datadir/geth/nodekey
- $GETH --verbosity=4 --datadir=$datadir --port=$((28000 + $i)) > geth.$i.log 2>&1 &
+ $GETH --verbosity=4 --datadir=$datadir --port=$((28000 + $i)) --rpc --rpcaddr 127.0.0.1 --rpcport=$((8545 + $i)) --rpcapi=eth,net,web3,debug --rpcvhosts='' --rpccorsdomain="https://www.myetherwallet.com" > geth.$i.log 2>&1 &
done
tail -f geth.*.log