Skip to content

Commit

Permalink
fix logs
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouop0 committed Feb 26, 2024
1 parent 598779f commit d618f9e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions docs/sql/listener.sql
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions internal/handler/checkstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
10 changes: 5 additions & 5 deletions internal/handler/committer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func Run(ctx *svc.ServiceContext) {
go SyncBlock(ctx)
// sync events
go SyncEvent(ctx)
// execute committer
//execute committer

Check failure on line 14 in internal/handler/handler.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)
go Committer(ctx)
// check status
go CheckStatus(ctx)
Expand Down
14 changes: 7 additions & 7 deletions internal/handler/inscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -42,20 +42,20 @@ 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)
bitcoinTxHash := rs.RevealTxHashList[0].String()

_, 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
Expand All @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/handler/syncProposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit d618f9e

Please sign in to comment.