Skip to content

Commit

Permalink
rpc:log_interceptor.go add params log
Browse files Browse the repository at this point in the history
  • Loading branch information
fengzi committed May 21, 2018
1 parent 4c33d5c commit 12ce204
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 39 deletions.
6 changes: 5 additions & 1 deletion common/dag/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"github.com/nebulasio/go-nebulas/util/logging"
"github.com/sirupsen/logrus"
)

//type value interface{}
Expand Down Expand Up @@ -76,7 +77,7 @@ func NewDispatcher(dag *Dag, concurrency int, elapseInMs int64, context interfac

// Run dag dispatch goroutine.
func (dp *Dispatcher) Run() error {
logging.VLog().Info("Starting Dag Dispatcher...")
logging.VLog().Debug("Starting Dag Dispatcher...")

vertices := dp.dag.GetNodes()

Expand Down Expand Up @@ -132,6 +133,9 @@ func (dp *Dispatcher) execute() error {
} else {
isFinish, err := dp.onCompleteParentTask(msg)
if err != nil {
logging.VLog().WithFields(logrus.Fields{
"err": err,
}).Debug("Stoped Dag Dispatcher.")
dp.Stop()
}
if isFinish {
Expand Down
53 changes: 29 additions & 24 deletions core/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (block *Block) FromProto(msg proto.Message) error {
logging.VLog().WithFields(logrus.Fields{
"blockHeight": msg.Height,
"compatibleHeight": RandomAvailableHeight,
}).Debug("No random found in block header.")
}).Info("No random found in block header.")
return ErrInvalidProtoToBlockHeader
}
block.transactions = make(Transactions, len(msg.Transactions))
Expand Down Expand Up @@ -552,7 +552,7 @@ func (block *Block) CollectTransactions(deadlineInMs int64) {
"block": block,
"tx": tx,
"err": err,
}).Debug("Failed to giveback the tx.")
}).Info("Failed to giveback the tx.")
}
return
}
Expand All @@ -566,15 +566,15 @@ func (block *Block) CollectTransactions(deadlineInMs int64) {
"block": block,
"tx": tx,
"err": err,
}).Debug("Failed to prepare tx.")
}).Info("Failed to prepare tx.")
failed++

if err := pool.Push(tx); err != nil {
logging.VLog().WithFields(logrus.Fields{
"block": block,
"tx": tx,
"err": err,
}).Debug("Failed to giveback the tx.")
}).Info("Failed to giveback the tx.")
}

fromBlacklist.Delete(tx.from.address.Hex())
Expand All @@ -592,7 +592,7 @@ func (block *Block) CollectTransactions(deadlineInMs int64) {
"block": block,
"tx": tx,
"err": err,
}).Debug("Failed to close tx.")
}).Info("Failed to close tx.")
}
}()

Expand Down Expand Up @@ -624,7 +624,7 @@ func (block *Block) CollectTransactions(deadlineInMs int64) {
"block": block,
"tx": tx,
"err": err,
}).Debug("Failed to giveback the tx.")
}).Info("Failed to giveback the tx.")
}
}
if err == ErrLargeTransactionNonce {
Expand Down Expand Up @@ -656,7 +656,7 @@ func (block *Block) CollectTransactions(deadlineInMs int64) {
"block": block,
"tx": tx,
"err": err,
}).Debug("Failed to giveback the tx.")
}).Info("Failed to giveback the tx.")
}
return
}
Expand All @@ -670,7 +670,7 @@ func (block *Block) CollectTransactions(deadlineInMs int64) {
"err": err,
"giveback": giveback,
"dependency": dependency,
}).Debug("CheckAndUpdate invalid tx.")
}).Info("CheckAndUpdate invalid tx.")
unpacked++
conflict++

Expand All @@ -679,7 +679,7 @@ func (block *Block) CollectTransactions(deadlineInMs int64) {
"block": block,
"tx": tx,
"err": err,
}).Debug("Failed to giveback the tx.")
}).Info("Failed to giveback the tx.")
}

fromBlacklist.Delete(tx.from.address.Hex())
Expand Down Expand Up @@ -753,7 +753,7 @@ func (block *Block) CollectTransactions(deadlineInMs int64) {
"core-packing": execute + prepare + update,
"packed": len(block.transactions),
"dag": block.dependency,
}).Debug("CollectTransactions")
}).Info("CollectTransactions")
}

// Sealed return true if block seals. Otherwise return false.
Expand Down Expand Up @@ -861,7 +861,7 @@ func (block *Block) VerifyExecution() error {
"diff-verify": commitAt - executedAt,
"block": block,
"txs": len(block.Transactions()),
}).Debug("Verify txs.")
}).Info("Verify txs.")

return nil
}
Expand All @@ -878,7 +878,7 @@ func (block *Block) VerifyIntegrity(chainID uint32, consensus Consensus) error {
logging.VLog().WithFields(logrus.Fields{
"expect": chainID,
"actual": block.header.chainID,
}).Debug("Failed to check chainid.")
}).Info("Failed to check chainid.")
metricsInvalidBlock.Inc(1)
return ErrInvalidChainID
}
Expand All @@ -889,7 +889,7 @@ func (block *Block) VerifyIntegrity(chainID uint32, consensus Consensus) error {
logging.VLog().WithFields(logrus.Fields{
"tx": tx,
"err": err,
}).Debug("Failed to verify tx's integrity.")
}).Info("Failed to verify tx's integrity.")
metricsInvalidBlock.Inc(1)
return err
}
Expand All @@ -905,7 +905,7 @@ func (block *Block) VerifyIntegrity(chainID uint32, consensus Consensus) error {
"expect": wantedHash,
"actual": block.Hash(),
"err": err,
}).Debug("Failed to check block's hash.")
}).Info("Failed to check block's hash.")
metricsInvalidBlock.Inc(1)
return ErrInvalidBlockHash
}
Expand All @@ -915,7 +915,7 @@ func (block *Block) VerifyIntegrity(chainID uint32, consensus Consensus) error {
logging.VLog().WithFields(logrus.Fields{
"block": block,
"err": err,
}).Debug("Failed to verify block.")
}).Info("Failed to verify block.")
metricsInvalidBlock.Inc(1)
return err
}
Expand All @@ -930,7 +930,7 @@ func (block *Block) verifyState() error {
logging.VLog().WithFields(logrus.Fields{
"expect": block.StateRoot(),
"actual": block.WorldState().AccountsRoot(),
}).Debug("Failed to verify state.")
}).Info("Failed to verify state.")
return ErrInvalidBlockStateRoot
}

Expand All @@ -939,7 +939,7 @@ func (block *Block) verifyState() error {
logging.VLog().WithFields(logrus.Fields{
"expect": block.TxsRoot(),
"actual": block.WorldState().TxsRoot(),
}).Debug("Failed to verify txs.")
}).Info("Failed to verify txs.")
return ErrInvalidBlockTxsRoot
}

Expand All @@ -948,7 +948,7 @@ func (block *Block) verifyState() error {
logging.VLog().WithFields(logrus.Fields{
"expect": block.EventsRoot(),
"actual": block.WorldState().EventsRoot(),
}).Debug("Failed to verify events.")
}).Info("Failed to verify events.")
return ErrInvalidBlockEventsRoot
}

Expand All @@ -957,7 +957,7 @@ func (block *Block) verifyState() error {
logging.VLog().WithFields(logrus.Fields{
"expect": block.ConsensusRoot(),
"actual": block.WorldState().ConsensusRoot(),
}).Debug("Failed to verify dpos context.")
}).Info("Failed to verify dpos context.")
return ErrInvalidBlockConsensusRoot
}
return nil
Expand Down Expand Up @@ -990,6 +990,11 @@ func (block *Block) execute() error {
return ErrInvalidDagBlock
}
tx := block.transactions[idx]

logging.VLog().WithFields(logrus.Fields{
"tx.hash": tx.hash,
}).Debug("execute tx.")

metricsTxExecute.Mark(1)

mergeCh <- true
Expand Down Expand Up @@ -1024,7 +1029,7 @@ func (block *Block) execute() error {
"dag": block.dependency.String(),
"txs": transactions,
"err": err,
}).Debug("Failed to verify txs in block.")
}).Info("Failed to verify txs in block.")
return err
}
end := time.Now().UnixNano()
Expand Down Expand Up @@ -1094,7 +1099,7 @@ func (block *Block) FetchExecutionResultEvent(txHash byteutils.Hash) (*state.Eve
logging.VLog().WithFields(logrus.Fields{
"tx": txHash,
"events": events,
}).Debug("Failed to locate the result event")
}).Info("Failed to locate the result event")
return nil, ErrInvalidTransactionResultEvent
}
return event, nil
Expand Down Expand Up @@ -1158,23 +1163,23 @@ func (block *Block) ExecuteTransaction(tx *Transaction, ws WorldState) (bool, er
logging.VLog().WithFields(logrus.Fields{
"tx": tx,
"err": err,
}).Debug("Failed to check transaction")
}).Info("Failed to check transaction")
return giveback, err
}

if giveback, err := VerifyExecution(tx, block, ws); err != nil {
logging.VLog().WithFields(logrus.Fields{
"tx": tx,
"err": err,
}).Debug("Failed to verify transaction execution")
}).Info("Failed to verify transaction execution")
return giveback, err
}

if giveback, err := AcceptTransaction(tx, ws); err != nil {
logging.VLog().WithFields(logrus.Fields{
"tx": tx,
"err": err,
}).Debug("Failed to accept transaction")
}).Info("Failed to accept transaction")
return giveback, err
}

Expand Down
18 changes: 17 additions & 1 deletion core/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,22 @@ func (tx *Transaction) String() string {
)
}

func (tx *Transaction) StringWithoutData() string {
return fmt.Sprintf(`{"chainID":%d, "hash":"%s", "from":"%s", "to":"%s", "nonce":%d, "value":"%s", "timestamp":%d, "gasprice": "%s", "gaslimit":"%s", "type":"%s"}`,
tx.chainID,
tx.hash.String(),
tx.from.String(),
tx.to.String(),
tx.nonce,
tx.value.String(),
tx.timestamp,
tx.gasPrice.String(),
tx.gasLimit.String(),
tx.Data(),
tx.Type(),
)
}

// JSONString of transaction
func (tx *Transaction) JSONString() string {
txJSONObj := make(map[string]interface{})
Expand Down Expand Up @@ -391,7 +407,7 @@ func submitTx(tx *Transaction, block *Block, ws WorldState,
"err": exeErr,
"block": block,
"transaction": tx,
}).Debug(exeErrTy)
}).Info(exeErrTy)
metricsTxExeFailed.Mark(1)
} else {
metricsTxExeSuccess.Mark(1)
Expand Down
10 changes: 5 additions & 5 deletions core/transaction_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (pool *TransactionPool) GetTransaction(hash byteutils.Hash) *Transaction {
func (pool *TransactionPool) PushAndRelay(tx *Transaction) error {
if err := pool.Push(tx); err != nil {
logging.VLog().WithFields(logrus.Fields{
"tx": tx,
"tx": tx.StringWithoutData(),
"err": err,
}).Debug("Failed to push tx")
return err
Expand All @@ -241,7 +241,7 @@ func (pool *TransactionPool) PushAndRelay(tx *Transaction) error {
func (pool *TransactionPool) PushAndBroadcast(tx *Transaction) error {
if err := pool.Push(tx); err != nil {
logging.VLog().WithFields(logrus.Fields{
"tx": tx,
"tx": tx.StringWithoutData(),
"err": err,
}).Debug("Failed to push tx")
return err
Expand Down Expand Up @@ -271,7 +271,7 @@ func (pool *TransactionPool) Push(tx *Transaction) error {
keyword = strings.ToLower(keyword)
if strings.Contains(data, keyword) {
logging.VLog().WithFields(logrus.Fields{
"tx": tx,
"tx.hash": tx.hash,
"unsupportedKeyword": keyword,
}).Debug("transaction data has unsupported keyword")
unsupportedKeywordError := fmt.Sprintf("transaction data has unsupported keyword(keyword: %s)", keyword)
Expand Down Expand Up @@ -316,7 +316,7 @@ func (pool *TransactionPool) Push(tx *Transaction) error {
pool.dropTx()

logging.VLog().WithFields(logrus.Fields{
"tx": tx,
"tx": tx.StringWithoutData(),
"size": pool.size,
"bpoolsize": poollen,
"apoolsize": len(pool.all),
Expand Down Expand Up @@ -524,7 +524,7 @@ func (pool *TransactionPool) evictExpiredTransactions() {
"size": pool.size,
"poolsize": len(pool.all),
"bucketsize": len(pool.buckets),
"tx": tx,
"tx": tx.StringWithoutData(),
}).Debug("Remove expired transactions.")
// trigger pending transaction
event := &state.Event{
Expand Down
18 changes: 10 additions & 8 deletions rpc/api_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,18 @@ func handleTransactionResponse(neb core.Neblet, tx *core.Transaction) (resp *rpc
}

// check Balance Simulate
if tx.Nonce() == (acc.Nonce() + 1) {
result, err := neb.BlockChain().SimulateTransactionExecution(tx)
if err != nil {
return nil, err
}
/*
if tx.Nonce() == (acc.Nonce() + 1) {
result, err := neb.BlockChain().SimulateTransactionExecution(tx)
if err != nil {
return nil, err
}
if result.Err != nil {
return nil, result.Err
if result.Err != nil {
return nil, result.Err
}
}
}
*/

if tx.Type() == core.TxPayloadDeployType {
if !tx.From().Equals(tx.To()) {
Expand Down
1 change: 1 addition & 0 deletions rpc/log_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func loggingStream(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServe
func loggingUnary(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
logging.VLog().WithFields(logrus.Fields{
"method": info.FullMethod,
"params": req,
}).Info("Rpc request.")
metricsRPCCounter.Mark(1)

Expand Down

0 comments on commit 12ce204

Please sign in to comment.