Commit 57a1fe88 authored by heyubin's avatar heyubin Committed by vipwzw

add by hyb for block-store-intable

parent ff49b480
...@@ -465,9 +465,13 @@ func (client *Client) CreateBlock() { ...@@ -465,9 +465,13 @@ func (client *Client) CreateBlock() {
newblock.ParentHash = lastBlock.Hash(cfg) newblock.ParentHash = lastBlock.Hash(cfg)
newblock.Height = lastBlock.Height + 1 newblock.Height = lastBlock.Height + 1
client.AddTxsToBlock(&newblock, txs) client.AddTxsToBlock(&newblock, txs)
//
newblock.Difficulty = cfg.GetP(0).PowLimitBits newblock.Difficulty = cfg.GetP(0).PowLimitBits
newblock.TxHash = merkle.CalcMerkleRoot(newblock.Txs)
//需要首先对交易进行排序然后再计算TxHash
if cfg.IsFork(newblock.Height, "ForkRootHash") {
newblock.Txs = types.TransactionSort(newblock.Txs)
}
newblock.TxHash = merkle.CalcMerkleRoot(cfg, newblock.Height, newblock.Txs)
newblock.BlockTime = client.blockTime newblock.BlockTime = client.blockTime
err := client.WriteBlock(lastBlock.StateHash, &newblock) err := client.WriteBlock(lastBlock.StateHash, &newblock)
......
...@@ -298,7 +298,7 @@ func (client *client) InitBlock() { ...@@ -298,7 +298,7 @@ func (client *client) InitBlock() {
} }
tx := client.CreateGenesisTx() tx := client.CreateGenesisTx()
newblock.Txs = tx newblock.Txs = tx
newblock.TxHash = merkle.CalcMerkleRoot(newblock.Txs) newblock.TxHash = merkle.CalcMerkleRoot(cfg, newblock.GetMainHeight(), newblock.Txs)
err := client.blockSyncClient.createGenesisBlock(newblock) err := client.blockSyncClient.createGenesisBlock(newblock)
if err != nil { if err != nil {
panic(fmt.Sprintf("para chain create genesis block,err=%s", err.Error())) panic(fmt.Sprintf("para chain create genesis block,err=%s", err.Error()))
......
...@@ -403,7 +403,11 @@ func (client *blockSyncClient) addBlock(lastBlock *types.Block, localBlock *pt.P ...@@ -403,7 +403,11 @@ func (client *blockSyncClient) addBlock(lastBlock *types.Block, localBlock *pt.P
} }
//挖矿固定难度 //挖矿固定难度
newBlock.Difficulty = cfg.GetP(0).PowLimitBits newBlock.Difficulty = cfg.GetP(0).PowLimitBits
newBlock.TxHash = merkle.CalcMerkleRoot(newBlock.Txs) //需要首先对交易进行排序然后再计算TxHash
if cfg.IsFork(newblock.GetMainHeight(), "ForkRootHash") {
newblock.Txs = types.TransactionSort(newblock.Txs)
}
newBlock.TxHash = merkle.CalcMerkleRoot(cfg, newBlock.GetMainHeight(), newBlock.Txs)
newBlock.BlockTime = localBlock.BlockTime newBlock.BlockTime = localBlock.BlockTime
newBlock.MainHash = localBlock.MainHash newBlock.MainHash = localBlock.MainHash
newBlock.MainHeight = localBlock.MainHeight newBlock.MainHeight = localBlock.MainHeight
......
...@@ -92,7 +92,11 @@ func (client *Client) CreateBlock() { ...@@ -92,7 +92,11 @@ func (client *Client) CreateBlock() {
newblock.ParentHash = lastBlock.Hash(cfg) newblock.ParentHash = lastBlock.Hash(cfg)
newblock.Height = lastBlock.Height + 1 newblock.Height = lastBlock.Height + 1
newblock.Txs = txs newblock.Txs = txs
newblock.TxHash = merkle.CalcMerkleRoot(newblock.Txs) //需要首先对交易进行排序
if cfg.IsFork(newblock.Height, "ForkRootHash") {
newblock.Txs = types.TransactionSort(newblock.Txs)
}
newblock.TxHash = merkle.CalcMerkleRoot(cfg, newblock.Height, newblock.Txs)
newblock.BlockTime = types.Now().Unix() newblock.BlockTime = types.Now().Unix()
if lastBlock.BlockTime >= newblock.BlockTime { if lastBlock.BlockTime >= newblock.BlockTime {
newblock.BlockTime = lastBlock.BlockTime + 1 newblock.BlockTime = lastBlock.BlockTime + 1
......
...@@ -184,7 +184,11 @@ func (client *Client) CreateBlock() { ...@@ -184,7 +184,11 @@ func (client *Client) CreateBlock() {
newblock.ParentHash = lastBlock.Hash(cfg) newblock.ParentHash = lastBlock.Hash(cfg)
newblock.Height = lastBlock.Height + 1 newblock.Height = lastBlock.Height + 1
client.AddTxsToBlock(&newblock, txs) client.AddTxsToBlock(&newblock, txs)
newblock.TxHash = merkle.CalcMerkleRoot(newblock.Txs) //需要首先对交易进行排序然后再计算TxHash
if cfg.IsFork(newblock.Height, "ForkRootHash") {
newblock.Txs = types.TransactionSort(newblock.Txs)
}
newblock.TxHash = merkle.CalcMerkleRoot(cfg, newblock.Height, newblock.Txs)
newblock.BlockTime = types.Now().Unix() newblock.BlockTime = types.Now().Unix()
if lastBlock.BlockTime >= newblock.BlockTime { if lastBlock.BlockTime >= newblock.BlockTime {
newblock.BlockTime = lastBlock.BlockTime + 1 newblock.BlockTime = lastBlock.BlockTime + 1
......
...@@ -747,8 +747,15 @@ func (cs *ConsensusState) createProposalBlock() (block *ttypes.TendermintBlock) ...@@ -747,8 +747,15 @@ func (cs *ConsensusState) createProposalBlock() (block *ttypes.TendermintBlock)
tendermintlog.Error("createProposalBlock createBaseTx fail") tendermintlog.Error("createProposalBlock createBaseTx fail")
return nil return nil
} }
cfg := cs.client.GetQueueClient().GetConfig()
block.Data.Txs[0] = baseTx block.Data.Txs[0] = baseTx
block.Data.TxHash = merkle.CalcMerkleRoot(block.Data.Txs) //需要首先对交易进行排序然后再计算TxHash
if cfg.IsFork(block.Data.Height, "ForkRootHash") {
block.Data.Txs = types.TransactionSort(block.Data.Txs)
}
block.Data.TxHash = merkle.CalcMerkleRoot(cfg, block.Data.Height, block.Data.Txs)
pblockNew := cs.client.PreExecBlock(block.Data, false) pblockNew := cs.client.PreExecBlock(block.Data, false)
if pblockNew == nil { if pblockNew == nil {
tendermintlog.Error("createProposalBlock PreExecBlock fail") tendermintlog.Error("createProposalBlock PreExecBlock fail")
......
...@@ -604,6 +604,12 @@ func (client *Client) Miner(parent, block *types.Block) error { ...@@ -604,6 +604,12 @@ func (client *Client) Miner(parent, block *types.Block) error {
if err != nil { if err != nil {
return err return err
} }
//需要首先对交易进行排序
cfg := client.GetAPI().GetConfig()
if cfg.IsFork(block.Height, "ForkRootHash") {
block.Txs = types.TransactionSort(block.Txs)
}
err = client.WriteBlock(parent.StateHash, block) err = client.WriteBlock(parent.StateHash, block)
if err != nil { if err != nil {
return err return err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment