Skip to content

Commit

Permalink
Log action activity
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc committed Oct 28, 2024
1 parent 17bc43f commit e7ee36b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
23 changes: 21 additions & 2 deletions api/coreservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"math"
"math/big"
"strconv"
"strings"
"time"

"github.com/ethereum/go-ethereum/core/vm"
Expand Down Expand Up @@ -299,7 +300,22 @@ func newCoreService(

if core.broadcastHandler != nil {
core.messageBatcher = batch.NewManager(func(msg *batch.Message) error {
return core.broadcastHandler(context.Background(), core.bc.ChainID(), msg.Data)
acts, ok := msg.Data.(*iotextypes.Actions)
sign := ""
if ok {
signs := make([]string, 0, len(acts.Actions))
for _, act := range acts.Actions {
signs = append(signs, hex.EncodeToString(act.Signature))
}
sign = strings.Join(signs, ",")
}
err := core.broadcastHandler(context.Background(), core.bc.ChainID(), msg.Data)
if err != nil {
log.L().Debug("fail to handle a batch message when calling back", zap.Error(err), zap.String("aggrSigns", sign))
} else {
log.L().Debug("successfully handle a batch message", zap.String("aggrSigns", sign))
}
return err
})
}

Expand Down Expand Up @@ -477,7 +493,7 @@ func (core *coreService) SendAction(ctx context.Context, in *iotextypes.Action)
if err != nil {
return "", err
}
l := log.Logger("api").With(zap.String("actionHash", hex.EncodeToString(hash[:])))
l := log.Logger("api").With(zap.String("actionHash", hex.EncodeToString(hash[:])), zap.String("sign", hex.EncodeToString(selp.Signature())))
if err = core.ap.Add(ctx, selp); err != nil {
txBytes, serErr := proto.Marshal(in)
if serErr != nil {
Expand All @@ -500,6 +516,7 @@ func (core *coreService) SendAction(ctx context.Context, in *iotextypes.Action)
}
return "", st.Err()
}
l.Debug("action added into actpool")
// If there is no error putting into local actpool, broadcast it to the network
if core.messageBatcher != nil {
err = core.messageBatcher.Put(&batch.Message{
Expand All @@ -512,6 +529,8 @@ func (core *coreService) SendAction(ctx context.Context, in *iotextypes.Action)
}
if err != nil {
l.Warn("Failed to broadcast SendAction request.", zap.Error(err))
} else {
l.Debug("SendAction request broadcasted.")
}
return hex.EncodeToString(hash[:]), nil
}
Expand Down
11 changes: 10 additions & 1 deletion chainservice/chainservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ package chainservice

import (
"context"
"encoding/hex"

"github.com/libp2p/go-libp2p-core/peer"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"
"google.golang.org/protobuf/proto"

"github.com/iotexproject/iotex-election/committee"
Expand Down Expand Up @@ -100,10 +102,17 @@ func (cs *ChainService) HandleAction(ctx context.Context, actPb *iotextypes.Acti
if err != nil {
return err
}
txHash, err := act.Hash()
if err != nil {
return err
}
l := log.L().With(zap.String("actionHash", hex.EncodeToString(txHash[:])), zap.String("sign", hex.EncodeToString(act.Signature())))
ctx = protocol.WithRegistry(ctx, cs.registry)
err = cs.actpool.Add(ctx, act)
if err != nil {
log.L().Debug(err.Error())
l.Debug("failed to add action to actpool from network", zap.Error(err))
} else {
l.Debug("added action to actpool from network")
}
return err
}
Expand Down
5 changes: 5 additions & 0 deletions state/factory/workingset.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,9 @@ func (ws *workingSet) pickAndRunActions(
continue
}
actionCtx, err := withActionCtx(ctxWithBlockContext, nextAction)
var actHash hash.Hash256
if err == nil {
actHash = protocol.MustGetActionCtx(actionCtx).ActionHash
for _, p := range reg.All() {
if validator, ok := p.(protocol.ActionValidator); ok {
if err = validator.Validate(actionCtx, nextAction.Action(), ws); err != nil {
Expand All @@ -587,6 +589,7 @@ func (ws *workingSet) pickAndRunActions(
}
}
if err != nil {
log.L().Debug("failed to validate action", zap.Error(err), log.Hex("actionHash", actHash[:]))
caller := nextAction.SenderAddress()
if caller == nil {
return nil, errors.New("failed to get address")
Expand All @@ -600,9 +603,11 @@ func (ws *workingSet) pickAndRunActions(
case nil:
// do nothing
case action.ErrGasLimit:
log.L().Debug("gas limit not enough", zap.Uint64("gasLimit", blkCtx.GasLimit), zap.Uint64("actionGasLimit", nextAction.GasLimit()), log.Hex("actionHash", actHash[:]))
actionIterator.PopAccount()
continue
case action.ErrChainID, errUnfoldTxContainer, errDeployerNotWhitelisted:
log.L().Debug("failed to run action", zap.Error(err), log.Hex("actionHash", actHash[:]))
if caller := nextAction.SenderAddress(); caller != nil {
ap.DeleteAction(caller)
}
Expand Down

0 comments on commit e7ee36b

Please sign in to comment.