Skip to content

Commit 269bac1

Browse files
committed
merge and fix conflicts
2 parents 108ddc8 + 5b787be commit 269bac1

File tree

7 files changed

+566
-791
lines changed

7 files changed

+566
-791
lines changed

core/types/block.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (n *BlockNonce) UnmarshalText(input []byte) error {
6969
type Header struct {
7070
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
7171
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
72-
Coinbase common.Address `json:"miner" gencodec:"required"`
72+
Coinbase common.Address `json:"miner"`
7373
Root common.Hash `json:"stateRoot" gencodec:"required"`
7474
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
7575
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`

core/types/gen_header_json.go

+4-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

miner/worker.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -891,12 +891,17 @@ func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Addres
891891

892892
// do not do CCC checks on follower nodes
893893
if w.isRunning() {
894+
// do gas limit check up-front and do not run CCC if it fails
895+
if w.current.gasPool.Gas() < tx.Gas() {
896+
return nil, nil, core.ErrGasLimitReached
897+
}
898+
894899
snap := w.current.state.Snapshot()
895900

896901
log.Trace(
897902
"Worker apply ccc for tx",
898903
"id", w.circuitCapacityChecker.ID,
899-
"txhash", tx.Hash(),
904+
"txHash", tx.Hash().Hex(),
900905
)
901906

902907
// 1. we have to check circuit capacity before `core.ApplyTransaction`,
@@ -922,7 +927,7 @@ func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Addres
922927
log.Trace(
923928
"Worker apply ccc for tx result",
924929
"id", w.circuitCapacityChecker.ID,
925-
"txhash", tx.Hash(),
930+
"txHash", tx.Hash().Hex(),
926931
"accRows", accRows,
927932
)
928933
}
@@ -933,6 +938,20 @@ func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Addres
933938
receipt, err := core.ApplyTransaction(w.chainConfig, w.chain, &coinbase, w.current.gasPool, w.current.state, w.current.header, tx, &w.current.header.GasUsed, *w.chain.GetVMConfig())
934939
if err != nil {
935940
w.current.state.RevertToSnapshot(snap)
941+
942+
if accRows != nil {
943+
// At this point, we have called CCC but the transaction failed in `ApplyTransaction`.
944+
// If we skip this tx and continue to pack more, the next tx will likely fail with
945+
// `circuitcapacitychecker.ErrUnknown`. However, at this point we cannot decide whether
946+
// we should seal the block or skip the tx and continue, so we simply return the error.
947+
log.Error(
948+
"GetBlockTrace passed but ApplyTransaction failed, ccc is left in inconsistent state",
949+
"blockNumber", w.current.header.Number,
950+
"txHash", tx.Hash().Hex(),
951+
"err", err,
952+
)
953+
}
954+
936955
return nil, traces, err
937956
}
938957

p2p/peer.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ type Peer struct {
112112
wg sync.WaitGroup
113113
protoErr chan error
114114
closed chan struct{}
115+
pingRecv chan struct{}
115116
disc chan DiscReason
116117

117118
// events receives message send / receive events if set
@@ -225,6 +226,7 @@ func newPeer(log log.Logger, conn *conn, protocols []Protocol) *Peer {
225226
disc: make(chan DiscReason),
226227
protoErr: make(chan error, len(protomap)+1), // protocols + pingLoop
227228
closed: make(chan struct{}),
229+
pingRecv: make(chan struct{}, 16),
228230
log: log.New("id", conn.node.ID(), "conn", conn.flags),
229231
}
230232
return p
@@ -285,9 +287,11 @@ loop:
285287
}
286288

287289
func (p *Peer) pingLoop() {
288-
ping := time.NewTimer(pingInterval)
289290
defer p.wg.Done()
291+
292+
ping := time.NewTimer(pingInterval)
290293
defer ping.Stop()
294+
291295
for {
292296
select {
293297
case <-ping.C:
@@ -296,6 +300,10 @@ func (p *Peer) pingLoop() {
296300
return
297301
}
298302
ping.Reset(pingInterval)
303+
304+
case <-p.pingRecv:
305+
SendItems(p.rw, pongMsg)
306+
299307
case <-p.closed:
300308
return
301309
}
@@ -322,7 +330,10 @@ func (p *Peer) handle(msg Msg) error {
322330
switch {
323331
case msg.Code == pingMsg:
324332
msg.Discard()
325-
go SendItems(p.rw, pongMsg)
333+
select {
334+
case p.pingRecv <- struct{}{}:
335+
case <-p.closed:
336+
}
326337
case msg.Code == discMsg:
327338
// This is the last message. We don't need to discard or
328339
// check errors because, the connection will be closed after it.

0 commit comments

Comments
 (0)