Commit 106dcf7d authored by vipwzw's avatar vipwzw

update seq bug

parent c2820b66
...@@ -1242,7 +1242,6 @@ func (bs *BlockStore) SetStoreUpgradeMeta(meta *types.UpgradeMeta) error { ...@@ -1242,7 +1242,6 @@ func (bs *BlockStore) SetStoreUpgradeMeta(meta *types.UpgradeMeta) error {
const ( const (
seqStatusOk = iota seqStatusOk = iota
seqStatusNeedCreate seqStatusNeedCreate
seqStatusNeedDelete
) )
//CheckSequenceStatus 配置的合法性检测 //CheckSequenceStatus 配置的合法性检测
...@@ -1267,25 +1266,12 @@ func (bs *BlockStore) CheckSequenceStatus(recordSequence bool) int { ...@@ -1267,25 +1266,12 @@ func (bs *BlockStore) CheckSequenceStatus(recordSequence bool) int {
storeLog.Error("CheckSequenceStatus", "lastHeight", lastHeight, "lastSequence", lastSequence) storeLog.Error("CheckSequenceStatus", "lastHeight", lastHeight, "lastSequence", lastSequence)
return seqStatusNeedCreate return seqStatusNeedCreate
} }
//通过lastSequence获取对应的blockhash != lastHeader.hash 报错
if lastSequence != -1 {
blockSequence, err := bs.GetBlockSequence(lastSequence)
if err != nil {
storeLog.Error("CheckSequenceStatus", "lastSequence", lastSequence, "GetBlockSequence err", err)
panic(err)
}
lastHeader := bs.LastHeader()
if !bytes.Equal(lastHeader.Hash, blockSequence.Hash) {
storeLog.Error("CheckSequenceStatus:", "lastHeight", lastHeight, "lastSequence", lastSequence, "lastHeader.Hash", common.ToHex(lastHeader.Hash), "blockSequence.Hash", common.ToHex(blockSequence.Hash))
return seqStatusNeedCreate
}
}
return seqStatusOk return seqStatusOk
} }
//去使能isRecordBlockSequence时的检测 //去使能isRecordBlockSequence时的检测
if lastSequence != -1 { if lastSequence != -1 {
storeLog.Error("CheckSequenceStatus", "lastSequence", lastSequence) storeLog.Error("CheckSequenceStatus", "lastSequence", lastSequence)
return seqStatusNeedDelete panic("can not disable isRecordBlockSequence")
} }
return seqStatusOk return seqStatusOk
} }
...@@ -1348,51 +1334,3 @@ func (bs *BlockStore) CreateSequences(batchSize int64) { ...@@ -1348,51 +1334,3 @@ func (bs *BlockStore) CreateSequences(batchSize int64) {
} }
storeLog.Info("CreateSequences done") storeLog.Info("CreateSequences done")
} }
//DeleteSequences 删除本地数据库里的sequence记录
func (bs *BlockStore) DeleteSequences(batchSize int64) {
lastSeq, err := bs.LoadBlockLastSequence()
if err != nil {
if err != types.ErrHeightNotExist {
storeLog.Error("DeleteSequences LoadBlockLastSequence", "error", err)
panic("DeleteSequences LoadBlockLastSequence" + err.Error())
}
}
storeLog.Info("DeleteSequences LoadBlockLastSequence", "start", lastSeq)
newBatch := bs.NewBatch(true)
for i := lastSeq; i >= 0; i-- {
seq := i
header, err := bs.GetBlockHeaderByHeight(i)
if err != nil {
storeLog.Error("DeleteSequences GetBlockHeaderByHeight", "height", i, "error", err)
panic("DeleteSequences GetBlockHeaderByHeight" + err.Error())
}
// seq->hash
newBatch.Delete(calcSequenceToHashKey(seq, bs.isParaChain))
// hash -> seq
newBatch.Delete(calcHashToSequenceKey(header.Hash, bs.isParaChain))
if lastSeq-i == batchSize {
storeLog.Info("DeleteSequences ", "height", i)
newBatch.Set(calcLastSeqKey(bs.isParaChain), types.Encode(&types.Int64{Data: i - 1}))
err = newBatch.Write()
if err != nil {
storeLog.Error("DeleteSequences newBatch.Write", "error", err)
panic("DeleteSequences newBatch.Write" + err.Error())
}
lastSeq = i - 1
newBatch.Reset()
}
}
// last seq
newBatch.Delete(calcLastSeqKey(bs.isParaChain))
err = newBatch.Write()
if err != nil {
storeLog.Error("DeleteSequences newBatch.Write", "error", err)
panic("DeleteSequences newBatch.Write" + err.Error())
}
storeLog.Info("DeleteSequences done")
}
...@@ -176,10 +176,4 @@ func TestSeqCreateAndDelete(t *testing.T) { ...@@ -176,10 +176,4 @@ func TestSeqCreateAndDelete(t *testing.T) {
seq, err = blockStore.GetSequenceByHash([]byte("0")) seq, err = blockStore.GetSequenceByHash([]byte("0"))
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, int64(0), seq) assert.Equal(t, int64(0), seq)
blockStore.saveSequence = false
blockStore.DeleteSequences(10)
seq, err = blockStore.LoadBlockLastSequence()
assert.NotNil(t, err)
assert.Equal(t, int64(-1), seq)
} }
...@@ -248,8 +248,6 @@ func (chain *BlockChain) InitBlockChain() { ...@@ -248,8 +248,6 @@ func (chain *BlockChain) InitBlockChain() {
seqStatus := chain.blockStore.CheckSequenceStatus(chain.isRecordBlockSequence) seqStatus := chain.blockStore.CheckSequenceStatus(chain.isRecordBlockSequence)
if seqStatus == seqStatusNeedCreate { if seqStatus == seqStatusNeedCreate {
chain.blockStore.CreateSequences(100000) chain.blockStore.CreateSequences(100000)
} else if seqStatus == seqStatusNeedDelete {
chain.blockStore.DeleteSequences(100000)
} }
//先缓存最新的128个block信息到cache中 //先缓存最新的128个block信息到cache中
......
...@@ -312,7 +312,7 @@ func addSignRawTxFlags(cmd *cobra.Command) { ...@@ -312,7 +312,7 @@ func addSignRawTxFlags(cmd *cobra.Command) {
cmd.Flags().StringP("key", "k", "", "private key (optional)") cmd.Flags().StringP("key", "k", "", "private key (optional)")
cmd.Flags().StringP("addr", "a", "", "account address (optional)") cmd.Flags().StringP("addr", "a", "", "account address (optional)")
cmd.Flags().StringP("expire", "e", "120s", "transaction expire time") cmd.Flags().StringP("expire", "e", "120s", "transaction expire time")
cmd.Flags().Float64P("fee", "f", 0, "transaction fee (optional)") cmd.Flags().Float64P("fee", "f", 0, "transaction fee (optional), auto set proper fee if not set or zero fee")
cmd.Flags().StringP("to", "t", "", "new to addr (optional)") cmd.Flags().StringP("to", "t", "", "new to addr (optional)")
// A duration string is a possibly signed sequence of // A duration string is a possibly signed sequence of
......
...@@ -86,6 +86,13 @@ func (wallet *Wallet) ProcSignRawTx(unsigned *types.ReqSignRawTx) (string, error ...@@ -86,6 +86,13 @@ func (wallet *Wallet) ProcSignRawTx(unsigned *types.ReqSignRawTx) (string, error
} }
if unsigned.Fee != 0 { if unsigned.Fee != 0 {
tx.Fee = unsigned.Fee tx.Fee = unsigned.Fee
} else {
//get proper fee if not set
proper, err := wallet.api.GetProperFee(nil)
if err != nil {
return "", err
}
tx.Fee = proper.ProperFee
} }
expire, err := types.ParseExpire(unsigned.GetExpire()) expire, err := types.ParseExpire(unsigned.GetExpire())
......
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