Commit 1867e2ed authored by vipwzw's avatar vipwzw Committed by 33cn

update chain33 04/25

parent 4c3c8249
...@@ -61,6 +61,7 @@ func (chain *BlockChain) ReExecBlock(startHeight, curHeight int64) { ...@@ -61,6 +61,7 @@ func (chain *BlockChain) ReExecBlock(startHeight, curHeight int64) {
} }
prevStateHash = blockdetail.Block.StateHash prevStateHash = blockdetail.Block.StateHash
} }
for i := startHeight; i <= curHeight; i++ { for i := startHeight; i <= curHeight; i++ {
blockdetail, err := chain.GetBlock(i) blockdetail, err := chain.GetBlock(i)
if err != nil { if err != nil {
...@@ -71,6 +72,20 @@ func (chain *BlockChain) ReExecBlock(startHeight, curHeight int64) { ...@@ -71,6 +72,20 @@ func (chain *BlockChain) ReExecBlock(startHeight, curHeight int64) {
if err != nil { if err != nil {
panic(fmt.Sprintf("execBlockEx height=%d err=%s, this not allow fail", i, err.Error())) panic(fmt.Sprintf("execBlockEx height=%d err=%s, this not allow fail", i, err.Error()))
} }
if chain.cfg.EnableReExecLocal {
// 保存tx信息到db中
newbatch := chain.blockStore.NewBatch(false)
err = chain.blockStore.AddTxs(newbatch, blockdetail)
if err != nil {
panic(fmt.Sprintf("execBlockEx connectBlock readd Txs fail height=%d err=%s, this not allow fail", i, err.Error()))
}
err = newbatch.Write()
if err != nil {
panic(err)
}
}
prevStateHash = block.StateHash prevStateHash = block.StateHash
//更新高度 //更新高度
err = chain.upgradeMeta(i) err = chain.upgradeMeta(i)
......
...@@ -32,6 +32,8 @@ batchsync=false ...@@ -32,6 +32,8 @@ batchsync=false
# 是否记录添加或者删除区块的序列,若节点作为主链节点,为平行链节点提供服务,需要设置为true # 是否记录添加或者删除区块的序列,若节点作为主链节点,为平行链节点提供服务,需要设置为true
isRecordBlockSequence=false isRecordBlockSequence=false
enableTxQuickIndex=false enableTxQuickIndex=false
# 升级storedb是否重新执行localdb
enableReExecLocal=false
[p2p] [p2p]
# P2P服务监听端口号 # P2P服务监听端口号
......
...@@ -48,6 +48,8 @@ isRecordBlockSequence=true ...@@ -48,6 +48,8 @@ isRecordBlockSequence=true
# 是否为平行链节点 # 是否为平行链节点
isParaChain=false isParaChain=false
enableTxQuickIndex=false enableTxQuickIndex=false
# 升级storedb是否重新执行localdb
enableReExecLocal=false
[p2p] [p2p]
# P2P服务监听端口号 # P2P服务监听端口号
......
...@@ -82,6 +82,11 @@ func (bc *BaseClient) GetAPI() client.QueueProtocolAPI { ...@@ -82,6 +82,11 @@ func (bc *BaseClient) GetAPI() client.QueueProtocolAPI {
return bc.api return bc.api
} }
//SetAPI ...
func (bc *BaseClient) SetAPI(api client.QueueProtocolAPI) {
bc.api = api
}
//InitClient 初始化 //InitClient 初始化
func (bc *BaseClient) InitClient(c queue.Client, minerstartCB func()) { func (bc *BaseClient) InitClient(c queue.Client, minerstartCB func()) {
log.Info("Enter SetQueueClient method of consensus") log.Info("Enter SetQueueClient method of consensus")
......
...@@ -117,26 +117,41 @@ func (mem *Mempool) checkTxs(msg *queue.Message) *queue.Message { ...@@ -117,26 +117,41 @@ func (mem *Mempool) checkTxs(msg *queue.Message) *queue.Message {
//checkTxList 检查账户余额是否足够,并加入到Mempool,成功则传入goodChan,若加入Mempool失败则传入badChan //checkTxList 检查账户余额是否足够,并加入到Mempool,成功则传入goodChan,若加入Mempool失败则传入badChan
func (mem *Mempool) checkTxRemote(msg *queue.Message) *queue.Message { func (mem *Mempool) checkTxRemote(msg *queue.Message) *queue.Message {
tx := msg.GetData().(types.TxGroup) tx := msg.GetData().(types.TxGroup)
txlist := &types.ExecTxList{}
txlist.Txs = append(txlist.Txs, tx.Tx())
//检查是否重复
lastheader := mem.GetHeader() lastheader := mem.GetHeader()
txlist.BlockTime = lastheader.BlockTime
txlist.Height = lastheader.Height //add check dup tx需要区分单笔交易/交易组
txlist.StateHash = lastheader.StateHash temtxlist := &types.ExecTxList{}
// 增加这个属性,在执行器中会使用到 txGroup, err := tx.GetTxGroup()
txlist.Difficulty = uint64(lastheader.Difficulty) if err != nil {
txlist.IsMempool = true msg.Data = err
//add check dup tx return msg
newtxs, err := util.CheckDupTx(mem.client, txlist.Txs, txlist.Height) }
if txGroup == nil {
temtxlist.Txs = append(temtxlist.Txs, tx.Tx())
} else {
temtxlist.Txs = append(temtxlist.Txs, txGroup.GetTxs()...)
}
temtxlist.Height = lastheader.Height
newtxs, err := util.CheckDupTx(mem.client, temtxlist.Txs, temtxlist.Height)
if err != nil { if err != nil {
msg.Data = err msg.Data = err
return msg return msg
} }
if len(newtxs) != len(txlist.Txs) { if len(newtxs) != len(temtxlist.Txs) {
msg.Data = types.ErrDupTx msg.Data = types.ErrDupTx
return msg return msg
} }
//exec模块检查交易
txlist := &types.ExecTxList{}
txlist.Txs = append(txlist.Txs, tx.Tx())
txlist.BlockTime = lastheader.BlockTime
txlist.Height = lastheader.Height
txlist.StateHash = lastheader.StateHash
// 增加这个属性,在执行器中会使用到
txlist.Difficulty = uint64(lastheader.Difficulty)
txlist.IsMempool = true
result, err := mem.checkTxListRemote(txlist) result, err := mem.checkTxListRemote(txlist)
if err != nil { if err != nil {
msg.Data = err msg.Data = err
......
...@@ -16,4 +16,6 @@ message Ticket { ...@@ -16,4 +16,6 @@ message Ticket {
string minerAddress = 6; string minerAddress = 6;
// return wallet // return wallet
string returnAddress = 7; string returnAddress = 7;
// miner Price
int64 price = 9;
} }
\ No newline at end of file
...@@ -35,7 +35,9 @@ type Ticket struct { ...@@ -35,7 +35,9 @@ type Ticket struct {
MinerValue int64 `protobuf:"varint,8,opt,name=minerValue,proto3" json:"minerValue,omitempty"` MinerValue int64 `protobuf:"varint,8,opt,name=minerValue,proto3" json:"minerValue,omitempty"`
MinerAddress string `protobuf:"bytes,6,opt,name=minerAddress,proto3" json:"minerAddress,omitempty"` MinerAddress string `protobuf:"bytes,6,opt,name=minerAddress,proto3" json:"minerAddress,omitempty"`
// return wallet // return wallet
ReturnAddress string `protobuf:"bytes,7,opt,name=returnAddress,proto3" json:"returnAddress,omitempty"` ReturnAddress string `protobuf:"bytes,7,opt,name=returnAddress,proto3" json:"returnAddress,omitempty"`
// miner Price
Price int64 `protobuf:"varint,9,opt,name=price,proto3" json:"price,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"` XXX_sizecache int32 `json:"-"`
...@@ -122,6 +124,13 @@ func (m *Ticket) GetReturnAddress() string { ...@@ -122,6 +124,13 @@ func (m *Ticket) GetReturnAddress() string {
return "" return ""
} }
func (m *Ticket) GetPrice() int64 {
if m != nil {
return m.Price
}
return 0
}
func init() { func init() {
proto.RegisterType((*Ticket)(nil), "ticket.Ticket") proto.RegisterType((*Ticket)(nil), "ticket.Ticket")
} }
...@@ -129,18 +138,18 @@ func init() { ...@@ -129,18 +138,18 @@ func init() {
func init() { proto.RegisterFile("ticket.proto", fileDescriptor_98a6c21780e82d22) } func init() { proto.RegisterFile("ticket.proto", fileDescriptor_98a6c21780e82d22) }
var fileDescriptor_98a6c21780e82d22 = []byte{ var fileDescriptor_98a6c21780e82d22 = []byte{
// 196 bytes of a gzipped FileDescriptorProto // 207 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x90, 0xb1, 0xae, 0x82, 0x30, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x90, 0xcd, 0x4a, 0xc4, 0x30,
0x14, 0x86, 0x53, 0xb8, 0xf4, 0xc2, 0x09, 0x77, 0xe9, 0x70, 0xd3, 0x18, 0x63, 0x1a, 0xe2, 0xd0, 0x14, 0x85, 0x49, 0x6b, 0x63, 0x7b, 0xa9, 0x9b, 0x8b, 0x48, 0x10, 0x91, 0x50, 0x5c, 0x64, 0xe5,
0xc9, 0xc5, 0x27, 0x70, 0x32, 0xae, 0x0d, 0x71, 0x47, 0x38, 0x43, 0xa3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0x19, 0xd7, 0xad, 0xed, 0xd0, 0x51, 0x9c, 0x50, 0x3c, 0x8b, 0x71, 0x4d, 0x5a, 0x98, 0xdc, 0x5e, 0x99, 0x6d, 0x3d, 0xba, 0x89, 0x3c, 0xc7, 0x05, 0xc7, 0xbb, 0xd8, 0xd6,
0x70, 0xae, 0x6e, 0x03, 0xca, 0x74, 0x5a, 0xcf, 0x46, 0x14, 0x90, 0x13, 0x1d, 0x9a, 0xc6, 0xa1, 0x0c, 0x5f, 0xdd, 0xef, 0x4a, 0xaa, 0x4c, 0xeb, 0xdd, 0x60, 0x03, 0x35, 0xd3, 0xfb, 0x30, 0x78,
0xf7, 0x92, 0xd3, 0x9f, 0x17, 0x4e, 0x6c, 0xe1, 0xcf, 0x61, 0x18, 0x5c, 0xf7, 0x2e, 0xfd, 0x52, 0x0a, 0x41, 0x49, 0x7e, 0xf3, 0xc1, 0xe1, 0x0b, 0xdc, 0x79, 0x8a, 0xab, 0x9f, 0xce, 0xa5, 0x5b,
0x69, 0x29, 0x2f, 0x9c, 0x6e, 0xb2, 0x7f, 0x06, 0x00, 0x00, 0xff, 0xff, 0x90, 0x22, 0xb8, 0x7d, 0x2e, 0x1d, 0x25, 0xde, 0x43, 0xb1, 0x78, 0xd7, 0x93, 0xaa, 0xf8, 0x92, 0x04, 0xdf, 0x92, 0x7f,
0x23, 0x01, 0x00, 0x00, 0xea, 0xed, 0x3f, 0x00, 0x00, 0xff, 0xff, 0xb6, 0xb4, 0xe8, 0x04, 0x39, 0x01, 0x00, 0x00,
} }
...@@ -140,6 +140,8 @@ type BlockChain struct { ...@@ -140,6 +140,8 @@ type BlockChain struct {
// 是否为平行链节点 // 是否为平行链节点
IsParaChain bool `protobuf:"varint,12,opt,name=isParaChain" json:"isParaChain,omitempty"` IsParaChain bool `protobuf:"varint,12,opt,name=isParaChain" json:"isParaChain,omitempty"`
EnableTxQuickIndex bool `protobuf:"varint,13,opt,name=enableTxQuickIndex" json:"enableTxQuickIndex,omitempty"` EnableTxQuickIndex bool `protobuf:"varint,13,opt,name=enableTxQuickIndex" json:"enableTxQuickIndex,omitempty"`
// 升级storedb是否重新执行localdb
EnableReExecLocal bool `protobuf:"varint,13,opt,name=enableReExecLocal" json:"enableReExecLocal,omitempty"`
} }
// P2P 配置 // P2P 配置
......
...@@ -207,12 +207,12 @@ func SetTestNetFork() { ...@@ -207,12 +207,12 @@ func SetTestNetFork() {
systemFork.SetFork("chain33", "ForkResetTx0", 453400) systemFork.SetFork("chain33", "ForkResetTx0", 453400)
systemFork.SetFork("chain33", "ForkExecRollback", 706531) systemFork.SetFork("chain33", "ForkExecRollback", 706531)
systemFork.SetFork("chain33", "ForkTxHeight", 806578) systemFork.SetFork("chain33", "ForkTxHeight", 806578)
systemFork.SetFork("chain33", "ForkTxGroupPara", 806578)
systemFork.SetFork("chain33", "ForkCheckBlockTime", 1200000) systemFork.SetFork("chain33", "ForkCheckBlockTime", 1200000)
systemFork.SetFork("chain33", "ForkMultiSignAddress", 1298600) systemFork.SetFork("chain33", "ForkMultiSignAddress", 1298600)
systemFork.SetFork("chain33", "ForkStateDBSet", 1572391) systemFork.SetFork("chain33", "ForkStateDBSet", 1572391)
systemFork.SetFork("chain33", "ForkBlockCheck", 1560000) systemFork.SetFork("chain33", "ForkBlockCheck", 1560000)
systemFork.SetFork("chain33", "ForkLocalDBAccess", 1572391) systemFork.SetFork("chain33", "ForkLocalDBAccess", 1572391)
systemFork.SetFork("chain33", "ForkTxGroupPara", 1687250)
} }
func setLocalFork() { func setLocalFork() {
......
...@@ -168,6 +168,7 @@ func (txgroup *Transactions) Check(height, minfee, maxFee int64) error { ...@@ -168,6 +168,7 @@ func (txgroup *Transactions) Check(height, minfee, maxFee int64) error {
} }
} }
//txgroup 只允许一条平行链的交易, 且平行链txgroup须全部是平行链tx //txgroup 只允许一条平行链的交易, 且平行链txgroup须全部是平行链tx
//如果平行链已经在主链分叉高度前运行了一段时间且有跨链交易,平行链需要自己设置这个fork
if IsFork(height, "ForkTxGroupPara") { if IsFork(height, "ForkTxGroupPara") {
if len(para) > 1 { if len(para) > 1 {
tlog.Info("txgroup has multi para transaction") tlog.Info("txgroup has multi para transaction")
......
...@@ -50,7 +50,7 @@ func TestCreateGroupTx(t *testing.T) { ...@@ -50,7 +50,7 @@ func TestCreateGroupTx(t *testing.T) {
func TestCreateParaGroupTx(t *testing.T) { func TestCreateParaGroupTx(t *testing.T) {
tempTitle := GetTitle() tempTitle := GetTitle()
SetTitleOnlyForTest("chain33") SetTitleOnlyForTest("chain33")
testHeight := int64(806578 + 1) testHeight := int64(1687250 + 1)
tx1 := "0a05636f696e73120e18010a0a1080c2d72f1a036f746520a08d0630f1cdebc8f7efa5e9283a22313271796f6361794e46374c7636433971573461767873324537553431664b536676" tx1 := "0a05636f696e73120e18010a0a1080c2d72f1a036f746520a08d0630f1cdebc8f7efa5e9283a22313271796f6361794e46374c7636433971573461767873324537553431664b536676"
tx2 := "0a05636f696e73120e18010a0a1080c2d72f1a036f746520a08d0630de92c3828ad194b26d3a22313271796f6361794e46374c7636433971573461767873324537553431664b536676" tx2 := "0a05636f696e73120e18010a0a1080c2d72f1a036f746520a08d0630de92c3828ad194b26d3a22313271796f6361794e46374c7636433971573461767873324537553431664b536676"
tx3 := "0a05636f696e73120e18010a0a1080c2d72f1a036f746520a08d0630b0d6c895c4d28efe5d3a22313271796f6361794e46374c7636433971573461767873324537553431664b536676" tx3 := "0a05636f696e73120e18010a0a1080c2d72f1a036f746520a08d0630b0d6c895c4d28efe5d3a22313271796f6361794e46374c7636433971573461767873324537553431664b536676"
......
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