Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checker for no transaction cost #3158

Open
wants to merge 9 commits into
base: sprint-1.14
Choose a base branch
from
1 change: 1 addition & 0 deletions code/go/0chain.net/chaincore/block/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var (
ErrPreviousStateUnavailable = common.NewError("prev_state_unavailable", "Previous state not available")
ErrPreviousStateNotComputed = common.NewError("prev_state_not_computed", "Previous state not computed")
ErrCostTooBig = common.NewError("cost_too_big", "Block cost is too big")
ErrCostNotFound = common.NewError("cost_not_found", "Cost if not defined for transaction")

// ErrPreviousBlockUnavailable - error for previous block is not available.
ErrPreviousBlockUnavailable = common.NewError(PreviousBlockUnavailable,
Expand Down
9 changes: 9 additions & 0 deletions code/go/0chain.net/miner/protocol_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
// InsufficientTxns - to indicate an error when the transactions are not sufficient to make a block
const InsufficientTxns = "insufficient_txns"

const NoTransactionCost = "no_transaction_cost"

// ErrLFBClientStateNil is returned when client state of latest finalized block is nil
var ErrLFBClientStateNil = errors.New("client state of latest finalized block is empty")

Expand Down Expand Up @@ -353,6 +355,9 @@ func (mc *Chain) VerifyBlock(ctx context.Context, b *block.Block) (
if err != nil {
return err
}
if c == math.MaxInt {
return block.ErrCostNotFound
}

cost += c
costs = append(costs, c)
Expand Down Expand Up @@ -1171,6 +1176,10 @@ func (mc *Chain) generateBlock(ctx context.Context, b *block.Block,
logging.Logger.Debug("Bad transaction cost", zap.Error(err), zap.String("txn_hash", txn.Hash))
break
}
if cost == math.MaxInt {
logging.Logger.Debug("No transaction cost", zap.Error(err), zap.String("txn_hash", txn.Hash))
return common.NewError(NoTransactionCost, fmt.Sprintf("No transaction cost for txn %v", txn.Hash))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to break here as we do in other places

}
if iterInfo.cost+cost >= mc.ChainConfig.MaxBlockCost() {
logging.Logger.Debug("generate block (too big cost, skipping)")
break
Expand Down