Commit b24eac06 authored by mdj33's avatar mdj33 Committed by vipwzw

correct linter err of golint govet ineffasign

parent 71f4916a
This diff is collapsed.
......@@ -112,7 +112,7 @@ func TestFilterTxsForPara(t *testing.T) {
Receipts: receipts,
}
para := &ParaClient{}
para := &client{}
rst := para.FilterTxsForPara(detail)
filterTxs := []*types.Transaction{tx3, tx4, tx5, tx6, txA, txB, txC}
assert.Equal(t, filterTxs, rst)
......
......@@ -21,8 +21,8 @@ var (
consensusInterval = 16 //about 1 new block interval
)
type CommitMsgClient struct {
paraClient *ParaClient
type commitMsgClient struct {
paraClient *client
waitMainBlocks int32
commitMsgNotify chan int64
delMsgNotify chan int64
......@@ -33,7 +33,7 @@ type CommitMsgClient struct {
quit chan struct{}
}
func (client *CommitMsgClient) handler() {
func (client *commitMsgClient) handler() {
var isSync bool
var notification []int64 //记录每次系统重启后 min and current height
var finishHeight int64
......@@ -185,7 +185,7 @@ out:
client.paraClient.wg.Done()
}
func (client *CommitMsgClient) calcCommitMsgTxs(notifications []*pt.ParacrossNodeStatus) (*types.Transaction, int64, error) {
func (client *commitMsgClient) calcCommitMsgTxs(notifications []*pt.ParacrossNodeStatus) (*types.Transaction, int64, error) {
txs, count, err := client.batchCalcTxGroup(notifications)
if err != nil {
txs, err = client.singleCalcTx((notifications)[0])
......@@ -199,7 +199,7 @@ func (client *CommitMsgClient) calcCommitMsgTxs(notifications []*pt.ParacrossNod
return txs, int64(count), nil
}
func (client *CommitMsgClient) getTxsGroup(txsArr *types.Transactions) (*types.Transaction, error) {
func (client *commitMsgClient) getTxsGroup(txsArr *types.Transactions) (*types.Transaction, error) {
if len(txsArr.Txs) < 2 {
tx := txsArr.Txs[0]
tx.Sign(types.SECP256K1, client.privateKey)
......@@ -224,7 +224,7 @@ func (client *CommitMsgClient) getTxsGroup(txsArr *types.Transactions) (*types.T
return newtx, nil
}
func (client *CommitMsgClient) batchCalcTxGroup(notifications []*pt.ParacrossNodeStatus) (*types.Transaction, int, error) {
func (client *commitMsgClient) batchCalcTxGroup(notifications []*pt.ParacrossNodeStatus) (*types.Transaction, int, error) {
var rawTxs types.Transactions
for _, status := range notifications {
tx, err := paracross.CreateRawCommitTx4MainChain(status, pt.ParaX, 0)
......@@ -242,7 +242,7 @@ func (client *CommitMsgClient) batchCalcTxGroup(notifications []*pt.ParacrossNod
return txs, len(notifications), nil
}
func (client *CommitMsgClient) singleCalcTx(status *pt.ParacrossNodeStatus) (*types.Transaction, error) {
func (client *commitMsgClient) singleCalcTx(status *pt.ParacrossNodeStatus) (*types.Transaction, error) {
tx, err := paracross.CreateRawCommitTx4MainChain(status, pt.ParaX, 0)
if err != nil {
plog.Error("para get commit tx", "block height", status.Height)
......@@ -258,7 +258,7 @@ func (client *CommitMsgClient) singleCalcTx(status *pt.ParacrossNodeStatus) (*ty
// if sendCommitMsgTx block quite long, write channel will be block in handle(), addBlock will not send new msg until rpc send over
// if sendCommitMsgTx block quite long, if delMsg occur, after send over, ignore previous tx succ or fail, new msg will be rcv and sent
// if sendCommitMsgTx fail, wait 1s resend the failed tx, if new tx rcv from ch, send the new one.
func (client *CommitMsgClient) sendCommitMsg(ch chan *types.Transaction) {
func (client *commitMsgClient) sendCommitMsg(ch chan *types.Transaction) {
var err error
var tx *types.Transaction
resendTimer := time.After(time.Second * 1)
......@@ -286,7 +286,7 @@ out:
client.paraClient.wg.Done()
}
func (client *CommitMsgClient) sendCommitMsgTx(tx *types.Transaction) error {
func (client *commitMsgClient) sendCommitMsgTx(tx *types.Transaction) error {
if tx == nil {
return nil
}
......@@ -319,7 +319,7 @@ func checkTxInMainBlock(targetTx *types.Transaction, detail *types.BlockDetail)
//当前未考虑获取key非常多失败的场景, 如果获取height非常多,block模块会比较大,但是使用完了就释放了
//如果有必要也可以考虑每次最多取20个一个txgroup,发送共识部分循环获取发送也没问题
func (client *CommitMsgClient) getNodeStatus(start, end int64) ([]*pt.ParacrossNodeStatus, error) {
func (client *commitMsgClient) getNodeStatus(start, end int64) ([]*pt.ParacrossNodeStatus, error) {
var ret []*pt.ParacrossNodeStatus
if start == 0 {
geneStatus, err := client.getGenesisNodeStatus()
......@@ -402,7 +402,7 @@ func (client *CommitMsgClient) getNodeStatus(start, end int64) ([]*pt.ParacrossN
}
func (client *CommitMsgClient) getGenesisNodeStatus() (*pt.ParacrossNodeStatus, error) {
func (client *commitMsgClient) getGenesisNodeStatus() (*pt.ParacrossNodeStatus, error) {
var status pt.ParacrossNodeStatus
req := &types.ReqBlocks{Start: 0, End: 0}
msg := client.paraClient.GetQueueClient().NewMessage("blockchain", types.EventGetBlocks, req)
......@@ -425,7 +425,7 @@ func (client *CommitMsgClient) getGenesisNodeStatus() (*pt.ParacrossNodeStatus,
return &status, nil
}
func (client *CommitMsgClient) onBlockAdded(height int64) error {
func (client *commitMsgClient) onBlockAdded(height int64) error {
select {
case client.commitMsgNotify <- height:
case <-client.quit:
......@@ -434,14 +434,14 @@ func (client *CommitMsgClient) onBlockAdded(height int64) error {
return nil
}
func (client *CommitMsgClient) onBlockDeleted(height int64) {
func (client *commitMsgClient) onBlockDeleted(height int64) {
select {
case client.delMsgNotify <- height:
case <-client.quit:
}
}
func (client *CommitMsgClient) onMainBlockAdded(block *types.BlockDetail) {
func (client *commitMsgClient) onMainBlockAdded(block *types.BlockDetail) {
select {
case client.mainBlockAdd <- block:
case <-client.quit:
......@@ -449,7 +449,7 @@ func (client *CommitMsgClient) onMainBlockAdded(block *types.BlockDetail) {
}
//only sync once, as main usually sync, here just need the first sync status after start up
func (client *CommitMsgClient) mainSync() error {
func (client *commitMsgClient) mainSync() error {
req := &types.ReqNil{}
reply, err := client.paraClient.grpcClient.IsSync(context.Background(), req)
if err != nil {
......@@ -466,7 +466,7 @@ func (client *CommitMsgClient) mainSync() error {
}
func (client *CommitMsgClient) getConsensusHeight(consensusRst chan *pt.ParacrossStatus) {
func (client *commitMsgClient) getConsensusHeight(consensusRst chan *pt.ParacrossStatus) {
ticker := time.NewTicker(time.Second * time.Duration(consensusInterval))
isSync := false
defer ticker.Stop()
......@@ -486,7 +486,7 @@ out:
}
ret, err := client.paraClient.paraClient.GetTitle(context.Background(),
&types.ReqString{types.GetTitle()})
&types.ReqString{Data: types.GetTitle()})
if err != nil {
plog.Error("getConsensusHeight ", "err", err.Error())
continue
......@@ -499,7 +499,7 @@ out:
client.paraClient.wg.Done()
}
func (client *CommitMsgClient) fetchPrivacyKey(ch chan crypto.PrivKey) {
func (client *commitMsgClient) fetchPrivacyKey(ch chan crypto.PrivKey) {
defer client.paraClient.wg.Done()
if client.paraClient.authAccount == "" {
close(ch)
......@@ -544,7 +544,7 @@ out:
}
func CheckMinerTx(current *types.BlockDetail) error {
func checkMinerTx(current *types.BlockDetail) error {
//检查第一个笔交易的execs, 以及执行状态
if len(current.Block.Txs) == 0 {
return types.ErrEmptyTx
......
......@@ -42,7 +42,7 @@ func init() {
type suiteParaCommitMsg struct {
// Include our basic suite logic.
suite.Suite
para *ParaClient
para *client
grpcCli *typesmocks.Chain33Client
q queue.Queue
block *blockchain.BlockChain
......@@ -70,7 +70,7 @@ func (s *suiteParaCommitMsg) initEnv(cfg *types.Config, sub *types.ConfigSubModu
s.store = store.New(cfg.Store, sub.Store)
s.store.SetQueueClient(q.Client())
s.para = New(cfg.Consensus, sub.Consensus["para"]).(*ParaClient)
s.para = New(cfg.Consensus, sub.Consensus["para"]).(*client)
s.grpcCli = &typesmocks.Chain33Client{}
//data := &types.Int64{1}
s.grpcCli.On("GetLastBlockSequence", mock.Anything, mock.Anything).Return(nil, errors.New("nil"))
......@@ -97,7 +97,7 @@ func (s *suiteParaCommitMsg) initEnv(cfg *types.Config, sub *types.ConfigSubModu
}
func walletProcess(q queue.Queue, para *ParaClient) {
func walletProcess(q queue.Queue, para *client) {
defer para.wg.Done()
client := q.Client()
......@@ -109,7 +109,7 @@ func walletProcess(q queue.Queue, para *ParaClient) {
return
case msg := <-client.Recv():
if msg.Ty == types.EventDumpPrivkey {
msg.Reply(client.NewMessage("", types.EventHeader, &types.ReplyString{"6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"}))
msg.Reply(client.NewMessage("", types.EventHeader, &types.ReplyString{Data: "6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"}))
}
}
}
......
......@@ -36,6 +36,7 @@ func init() {
drivers.QueryData.Register("ticket", &Client{})
}
// Client export ticket client struct
type Client struct {
*drivers.BaseClient
//ticket list for miner
......@@ -57,6 +58,7 @@ type subConfig struct {
Genesis []*genesisTicket `json:"genesis"`
}
// New ticket's init env
func New(cfg *types.Consensus, sub []byte) queue.Module {
c := drivers.NewBaseClient(cfg)
var subcfg subConfig
......@@ -86,12 +88,14 @@ Loop:
}
}
// Close ticket close
func (client *Client) Close() {
close(client.done)
client.BaseClient.Close()
tlog.Info("consensus ticket closed")
}
// CreateGenesisTx ticket create genesis tx
func (client *Client) CreateGenesisTx() (ret []*types.Transaction) {
for _, genesis := range client.subcfg.Genesis {
tx1 := createTicket(genesis.MinerAddr, genesis.ReturnAddr, genesis.Count, 0)
......@@ -119,7 +123,7 @@ func createTicket(minerAddr, returnAddr string, count int32, height int64) (ret
tx2.To = driver.ExecAddress("ticket")
//gen payload
g = &cty.CoinsAction_Genesis{}
g.Genesis = &types.AssetsGenesis{int64(count) * types.GetP(height).TicketPrice, returnAddr}
g.Genesis = &types.AssetsGenesis{Amount: int64(count) * types.GetP(height).TicketPrice, ReturnAddress: returnAddr}
tx2.Payload = types.Encode(&cty.CoinsAction{Value: g, Ty: cty.CoinsActionGenesis})
ret = append(ret, &tx2)
......@@ -127,26 +131,29 @@ func createTicket(minerAddr, returnAddr string, count int32, height int64) (ret
tx3.Execer = []byte("ticket")
tx3.To = driver.ExecAddress("ticket")
gticket := &ty.TicketAction_Genesis{}
gticket.Genesis = &ty.TicketGenesis{minerAddr, returnAddr, count}
gticket.Genesis = &ty.TicketGenesis{MinerAddress: minerAddr, ReturnAddress: returnAddr, Count: count}
tx3.Payload = types.Encode(&ty.TicketAction{Value: gticket, Ty: ty.TicketActionGenesis})
ret = append(ret, &tx3)
return ret
}
// Query_GetTicketCount ticket query ticket count function
func (client *Client) Query_GetTicketCount(req *types.ReqNil) (types.Message, error) {
var ret types.Int64
ret.Data = client.getTicketCount()
return &ret, nil
}
// Query_FlushTicket ticket query flush ticket function
func (client *Client) Query_FlushTicket(req *types.ReqNil) (types.Message, error) {
err := client.flushTicket()
if err != nil {
return nil, err
}
return &types.Reply{true, []byte("OK")}, nil
return &types.Reply{IsOk: true, Msg: []byte("OK")}, nil
}
// ProcEvent ticket reply not support action err
func (client *Client) ProcEvent(msg queue.Message) bool {
msg.ReplyErr("Client", types.ErrActionNotSupport)
return true
......@@ -207,7 +214,7 @@ func (client *Client) flushTicket() error {
tlog.Error("flushTicket error", "err", err)
return err
}
client.setTicket(&ty.ReplyTicketList{tickets}, getPrivMap(privs))
client.setTicket(&ty.ReplyTicketList{Tickets: tickets}, getPrivMap(privs))
return nil
}
......@@ -242,7 +249,7 @@ func (client *Client) getMinerTx(current *types.Block) (*ty.TicketAction, error)
return &ticketAction, nil
}
func (client *Client) getModify(block *types.Block) ([]byte, error) {
func (client *Client) getMinerModify(block *types.Block) ([]byte, error) {
ticketAction, err := client.getMinerTx(block)
if err != nil {
return defaultModify, err
......@@ -250,7 +257,7 @@ func (client *Client) getModify(block *types.Block) ([]byte, error) {
return ticketAction.GetMiner().GetModify(), nil
}
func (client *Client) GetModify(beg, end int64) ([]byte, error) {
func (client *Client) getModify(beg, end int64) ([]byte, error) {
//通过某个区间计算modify
timeSource := int64(0)
total := int64(0)
......@@ -280,6 +287,7 @@ func (client *Client) GetModify(beg, end int64) ([]byte, error) {
return []byte(modify), nil
}
// CheckBlock ticket implete checkblock func
func (client *Client) CheckBlock(parent *types.Block, current *types.BlockDetail) error {
cfg := types.GetP(current.Block.Height)
if current.Block.BlockTime-types.Now().Unix() > cfg.FutureBlockTime {
......@@ -348,7 +356,7 @@ func (client *Client) getNextTarget(block *types.Block, bits uint32) (*big.Int,
powLimit := difficulty.CompactToBig(types.GetP(0).PowLimitBits)
return powLimit, defaultModify, nil
}
targetBits, modify, err := client.GetNextRequiredDifficulty(block, bits)
targetBits, modify, err := client.getNextRequiredDifficulty(block, bits)
if err != nil {
return nil, nil, err
}
......@@ -370,7 +378,7 @@ func (client *Client) getCurrentTarget(blocktime int64, id string, modify []byte
// This function differs from the exported CalcNextRequiredDifficulty in that
// the exported version uses the current best chain as the previous block node
// while this function accepts any block node.
func (client *Client) GetNextRequiredDifficulty(block *types.Block, bits uint32) (uint32, []byte, error) {
func (client *Client) getNextRequiredDifficulty(block *types.Block, bits uint32) (uint32, []byte, error) {
// Genesis block.
if block == nil {
return types.GetP(0).PowLimitBits, defaultModify, nil
......@@ -382,7 +390,7 @@ func (client *Client) GetNextRequiredDifficulty(block *types.Block, bits uint32)
if (block.Height+1) <= blocksPerRetarget || (block.Height+1)%blocksPerRetarget != 0 {
// For the main network (or any unrecognized networks), simply
// return the previous block's difficulty requirements.
modify, err := client.getModify(block)
modify, err := client.getMinerModify(block)
if err != nil {
return bits, defaultModify, err
}
......@@ -399,7 +407,7 @@ func (client *Client) GetNextRequiredDifficulty(block *types.Block, bits uint32)
return cfg.PowLimitBits, defaultModify, types.ErrBlockNotFound
}
modify, err := client.GetModify(block.Height+1-blocksPerRetarget, block.Height)
modify, err := client.getModify(block.Height+1-blocksPerRetarget, block.Height)
if err != nil {
return cfg.PowLimitBits, defaultModify, err
}
......@@ -443,7 +451,7 @@ func (client *Client) GetNextRequiredDifficulty(block *types.Block, bits uint32)
tlog.Info("Timespan", "Actual timespan", time.Duration(actualTimespan)*time.Second,
"adjusted timespan", time.Duration(adjustedTimespan)*time.Second,
"target timespan", cfg.TargetTimespan)
prevmodify, err := client.getModify(block)
prevmodify, err := client.getMinerModify(block)
if err != nil {
panic(err)
}
......@@ -511,6 +519,7 @@ func (client *Client) delTicket(ticket *ty.Ticket, index int) {
}
}
// Miner ticket miner function
func (client *Client) Miner(parent, block *types.Block) bool {
//add miner address
ticket, priv, diff, modify, index, err := client.searchTargetTicket(parent, block)
......@@ -577,7 +586,7 @@ func (client *Client) addMinerTx(parent, block *types.Block, diff *big.Int, priv
return err
}
miner.PrivHash = privHash
ticketAction.Value = &ty.TicketAction_Miner{miner}
ticketAction.Value = &ty.TicketAction_Miner{Miner: miner}
ticketAction.Ty = ty.TicketActionMiner
//构造transaction
tx := client.createMinerTx(&ticketAction, priv)
......@@ -648,6 +657,7 @@ func (client *Client) updateBlock(newblock *types.Block, txHashList [][]byte) (*
return lastBlock, txHashList
}
// CreateBlock ticket create block func
func (client *Client) CreateBlock() {
for {
if !client.IsMining() || !(client.IsCaughtUp() || client.Cfg.ForceMining) {
......
......@@ -226,11 +226,11 @@ func commitOnce(suite *CommitTestSuite, privkeyStr string) (receipt *types.Recei
}
func commitOnceImpl(suite suite.Suite, exec *Paracross, privkeyStr string) (receipt *types.Receipt) {
tx, err := fillRawCommitTx(suite)
tx, err = signTx(suite, tx, privkeyStr)
tx, _ := fillRawCommitTx(suite)
tx, _ = signTx(suite, tx, privkeyStr)
suite.T().Log(tx.From())
receipt, err = exec.Exec(tx, 0)
receipt, err := exec.Exec(tx, 0)
suite.T().Log(receipt)
assert.NotNil(suite.T(), receipt)
assert.Nil(suite.T(), err)
......@@ -526,7 +526,7 @@ func createTxsGroup(s suite.Suite, txs []*types.Transaction) ([]*types.Transacti
if err != nil {
return nil, err
}
privKey, err := getPrivKey(s, PrivKeyA)
privKey, _ := getPrivKey(s, PrivKeyA)
for i := range group.Txs {
group.SignN(i, int32(types.SECP256K1), privKey)
}
......
......@@ -67,9 +67,12 @@ func NewRelayd(config *Config) *Relayd {
}
currentHeight, err := db.Get(currentBtcBlockheightKey[:])
if err != nil {
log.Warn("NewRelayd", "db get error: ", err.Error())
}
height, err := strconv.Atoi(string(currentHeight))
if err != nil {
log.Warn("NewRelayd", "atoi height error: ", err)
log.Warn("NewRelayd", "atoi height error: ", err.Error())
}
if height < firstHeight || isResetBtcHeight {
......
......@@ -80,7 +80,7 @@ func (s *suiteBtcStore) TestSaveBlockHead() {
Time: 1231731025,
Height: 2,
}
val, err := proto.Marshal(head)
val, _ := proto.Marshal(head)
key := calcBtcHeaderKeyHash(head.Hash)
kv = append(kv, &types.KeyValue{key, val})
key = calcBtcHeaderKeyHeight(int64(head.Height))
......
......@@ -451,6 +451,10 @@ func (action *relayDB) confirmTx(confirm *ty.RelayConfirmTx) (*types.Receipt, er
//report Error if coinTxHash has been used and not same orderId, if same orderId, means to modify the txHash
coinTxOrder, err := action.getOrderByCoinHash([]byte(calcCoinHash(confirm.TxHash)))
if err != nil {
relaylog.Error("confirmTx getOrderByCoinHash", "orderid", confirm.OrderId, "err", err.Error())
return nil, err
}
if coinTxOrder != nil {
if coinTxOrder.Id != confirm.OrderId {
relaylog.Error("confirmTx", "coinTxHash", confirm.TxHash, "has been used in other order", coinTxOrder.Id)
......
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