From d618f9e3351f0645a1a4c1e10e18a993648eba6b Mon Sep 17 00:00:00 2001 From: zhouop0 <11733741+zhouop0@users.noreply.github.com> Date: Mon, 26 Feb 2024 14:52:03 +0800 Subject: [PATCH] fix logs --- docs/sql/listener.sql | 4 ++-- internal/handler/checkstatus.go | 4 ++-- internal/handler/committer.go | 10 +++++----- internal/handler/handler.go | 2 +- internal/handler/inscribe.go | 14 +++++++------- internal/handler/syncProposal.go | 2 +- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/sql/listener.sql b/docs/sql/listener.sql index 1691611..9e62e7f 100644 --- a/docs/sql/listener.sql +++ b/docs/sql/listener.sql @@ -1,5 +1,5 @@ -Create Database If Not Exists b2_committer3 Character Set UTF8; -USE b2_committer3; +Create Database If Not Exists b2_committer Character Set UTF8; +USE b2_committer; SET NAMES utf8mb4; diff --git a/internal/handler/checkstatus.go b/internal/handler/checkstatus.go index 92a768c..c22516a 100644 --- a/internal/handler/checkstatus.go +++ b/internal/handler/checkstatus.go @@ -15,13 +15,13 @@ func CheckStatus(ctx *svc.ServiceContext) { var dbProposal schema.Proposal err := ctx.DB.Where("status=?", schema.VotingStatus).Order("end_batch_num asc").First(&dbProposal).Error if err != nil { - log.Errorf("[Handler.CheckStatus] find Voting proposal err: %s\n", errors.WithStack(err)) + log.Errorf("[Handler.CheckStatus] find Voting proposal err: %s\n", errors.WithStack(err).Error()) time.Sleep(5 * time.Second) continue } proposal, err := ctx.NodeClient.QueryProposalByID(dbProposal.ProposalID) if err != nil { - log.Errorf("[Handler.CheckStatus] QueryProposalByID err: %s\n", errors.WithStack(err)) + log.Errorf("[Handler.CheckStatus] QueryProposalByID err: %s\n", errors.WithStack(err).Error()) continue } if proposal.Status != schema.VotingStatus && proposal.Winner != "" { diff --git a/internal/handler/committer.go b/internal/handler/committer.go index ef19d53..2bfd927 100644 --- a/internal/handler/committer.go +++ b/internal/handler/committer.go @@ -52,7 +52,7 @@ func Committer(ctx *svc.ServiceContext) { } err = ctx.DB.Where("end_batch_num > ?", lastFinalBatchNum).Find(&proposals).Error if err != nil { - log.Errorf("[Handler.Committer][DB] error info:", errors.WithStack(err)) + log.Errorf("[Handler.Committer][DB] error info: %s", errors.WithStack(err).Error()) time.Sleep(10 * time.Second) continue } @@ -62,17 +62,17 @@ func Committer(ctx *svc.ServiceContext) { } verifyBatchInfo, err := GetVerifyBatchInfoByLastBatchNum(ctx, lastFinalBatchNum) if err != nil { - log.Errorf("[Handler.Committer] error info:", errors.WithStack(err)) + log.Errorf("[Handler.Committer] error info: %s", errors.WithStack(err).Error()) time.Sleep(10 * time.Second) continue } err = committerProposal(ctx, verifyBatchInfo, lastProposalID) if err != nil { - log.Errorf("[Handler.Committer] error info:", errors.WithStack(err)) + log.Errorf("[Handler.Committer] error info: %s", errors.WithStack(err).Error()) time.Sleep(10 * time.Second) continue } - time.Sleep(10 * time.Second) + time.Sleep(3 * time.Second) } } @@ -170,7 +170,7 @@ func GetMerkleStateRootsAndProofs(params []*VerifyBatchesTrustedAggregatorParams func GetVerifyBatchesFromStartBatchNum(ctx *svc.ServiceContext, startBatchNum uint64, limit int) ([]*VerifyBatchesAndTxHash, error) { events := make([]schema.SyncEvent, 0, limit) err := ctx.DB.Table("sync_events").Select("*, JSON_EXTRACT(data, '$.numBatch') as numBatch"). - Where("JSON_EXTRACT(data, '$.numBatch') >= ?", startBatchNum).Order("numBatch").Limit(limit).Find(&events).Error + Where("JSON_EXTRACT(data, '$.numBatch') > ?", startBatchNum).Order("numBatch").Limit(limit).Find(&events).Error if err != nil { return nil, fmt.Errorf("[GetVerifyBatchesFromStartBatchNum] dbbase err: %s", err) } diff --git a/internal/handler/handler.go b/internal/handler/handler.go index 7e22698..5fc2581 100644 --- a/internal/handler/handler.go +++ b/internal/handler/handler.go @@ -11,7 +11,7 @@ func Run(ctx *svc.ServiceContext) { go SyncBlock(ctx) // sync events go SyncEvent(ctx) - // execute committer + //execute committer go Committer(ctx) // check status go CheckStatus(ctx) diff --git a/internal/handler/inscribe.go b/internal/handler/inscribe.go index 96ed270..ba15f2f 100644 --- a/internal/handler/inscribe.go +++ b/internal/handler/inscribe.go @@ -23,13 +23,13 @@ func Inscribe(ctx *svc.ServiceContext) { var dbProposal schema.Proposal err := ctx.DB.Where("status=?", schema.PendingStatus).Order("end_batch_num asc").First(&dbProposal).Error if err != nil { - log.Errorf("[Handler.Inscribe] Pending and timeout proposal err: %s\n", errors.WithStack(err)) + log.Errorf("[Handler.Inscribe] Pending and timeout proposal err: %s\n", errors.WithStack(err).Error()) time.Sleep(5 * time.Second) continue } proposal, err := ctx.NodeClient.QueryProposalByID(dbProposal.ProposalID) if err != nil { - log.Errorf("[CheckProposalPending] QueryProposalByID err: %s\n", errors.WithStack(err)) + log.Errorf("[CheckProposalPending] QueryProposalByID err: %s\n", errors.WithStack(err).Error()) continue } if proposal.Status == schema.SucceedStatus { @@ -42,12 +42,12 @@ func Inscribe(ctx *svc.ServiceContext) { proposal.Winner == ctx.B2NodeConfig.Address && proposal.BitcoinTxHash == "" { rs, err := inscribe.Inscribe(ctx.BTCConfig.PrivateKey, proposal.StateRootHash, proposal.ProofHash, ctx.BTCConfig.DestinationAddress, btcapi.ChainParams(ctx.BTCConfig.NetworkName)) if err != nil { - log.Errorf("[Handler.Inscribe] Inscribe err: %s\n", errors.WithStack(err)) + log.Errorf("[Handler.Inscribe] Inscribe err: %s\n", errors.WithStack(err).Error()) continue } str, err := json.Marshal(rs) if err != nil { - log.Errorf("[Handler.Inscribe] Marshal result err: %s\n", errors.WithStack(err)) + log.Errorf("[Handler.Inscribe] Marshal result err: %s\n", errors.WithStack(err).Error()) continue } log.Infof("[Handler.Inscribe] inscribe result: %s", str) @@ -55,7 +55,7 @@ func Inscribe(ctx *svc.ServiceContext) { _, err = ctx.NodeClient.BitcoinTx(proposal.Id, proposal.Winner, bitcoinTxHash) if err != nil { - log.Errorf("[Handler.Inscribe] BitcoinTx err: %s\n", errors.WithStack(err)) + log.Errorf("[Handler.Inscribe] BitcoinTx err: %s\n", errors.WithStack(err).Error()) continue } dbProposal.BtcRevealTxHash = bitcoinTxHash @@ -68,13 +68,13 @@ func Inscribe(ctx *svc.ServiceContext) { btcAPIClient := btcmempool.NewClient(btcapi.ChainParams(ctx.BTCConfig.NetworkName)) transaction, err := btcAPIClient.GetTransactionByID(proposal.BitcoinTxHash) if err != nil { - log.Errorf("[Handler.Inscribe] GetTransactionByID err: %s\n", errors.WithStack(err)) + log.Errorf("[Handler.Inscribe] GetTransactionByID err: %s\n", errors.WithStack(err).Error()) continue } if transaction.Status.Confirmed && (ctx.LatestBTCBlockNumber-transaction.Status.BlockHeight) >= 6 { _, err = ctx.NodeClient.BitcoinTx(proposal.Id, proposal.Proposer, proposal.BitcoinTxHash) if err != nil { - log.Errorf("[Handler.Inscribe] BitcoinTx err: %s\n", errors.WithStack(err)) + log.Errorf("[Handler.Inscribe] BitcoinTx err: %s\n", errors.WithStack(err).Error()) continue } } diff --git a/internal/handler/syncProposal.go b/internal/handler/syncProposal.go index ed0b3dd..992b61a 100644 --- a/internal/handler/syncProposal.go +++ b/internal/handler/syncProposal.go @@ -17,7 +17,7 @@ func SyncProposal(ctx *svc.ServiceContext) { for { lastProposalID, _, err := ctx.NodeClient.QueryLastProposalID() if err != nil { - log.Errorf("[Handler.Committer][QueryLastProposalID] error info:", errors.WithStack(err)) + log.Errorf("[Handler.Committer][QueryLastProposalID] error info: %s", errors.WithStack(err).Error()) time.Sleep(3 * time.Second) continue }