Skip to content

Commit

Permalink
sentry reject conditional transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
pratikspatil024 committed Aug 11, 2023
1 parent 7d837dc commit c4e0a5c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
4 changes: 4 additions & 0 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ func (b *EthAPIBackend) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscri
}

func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error {
if signedTx.GetOptions() != nil && !b.eth.Miner().GetWorker().IsRunning() {
return errors.New("bundled transactions are not broadcasted therefore they will not submitted to the transaction pool")

Check warning on line 317 in eth/api_backend.go

View check run for this annotation

Codecov / codecov/patch

eth/api_backend.go#L316-L317

Added lines #L316 - L317 were not covered by tests
}

err := b.eth.txPool.AddLocal(signedTx)
if err != nil {
if unwrapped := errors.Unwrap(err); unwrapped != nil {
Expand Down
6 changes: 5 additions & 1 deletion miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func New(eth Backend, config *Config, chainConfig *params.ChainConfig, mux *even
return miner
}

func (miner *Miner) GetWorker() *worker {
return miner.worker

Check warning on line 107 in miner/miner.go

View check run for this annotation

Codecov / codecov/patch

miner/miner.go#L107

Added line #L107 was not covered by tests
}

// update keeps track of the downloader events. Please be aware that this is a one shot type of update loop.
// It's entered once and as soon as `Done` or `Failed` has been broadcasted the events are unregistered and
// the loop is exited. This to prevent a major security vuln where external parties can DOS you with blocks
Expand Down Expand Up @@ -189,7 +193,7 @@ func (miner *Miner) Close() {
}

func (miner *Miner) Mining() bool {
return miner.worker.isRunning()
return miner.worker.IsRunning()
}

func (miner *Miner) Hashrate() uint64 {
Expand Down
8 changes: 4 additions & 4 deletions miner/test_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func (w *worker) mainLoopWithDelay(ctx context.Context, delay uint, opcodeDelay
// If our sealing block contains less than 2 uncle blocks,
// add the new uncle block if valid and regenerate a new
// sealing block for higher profit.
if w.isRunning() && w.current != nil && len(w.current.uncles) < 2 {
if w.IsRunning() && w.current != nil && len(w.current.uncles) < 2 {

Check warning on line 395 in miner/test_backend.go

View check run for this annotation

Codecov / codecov/patch

miner/test_backend.go#L395

Added line #L395 was not covered by tests
start := time.Now()
if err := w.commitUncle(w.current, ev.Block.Header()); err == nil {
commitErr := w.commit(ctx, w.current.copy(), nil, true, start)
Expand Down Expand Up @@ -423,7 +423,7 @@ func (w *worker) mainLoopWithDelay(ctx context.Context, delay uint, opcodeDelay
// already included in the current sealing block. These transactions will
// be automatically eliminated.
// nolint : nestif
if !w.isRunning() && w.current != nil {
if !w.IsRunning() && w.current != nil {
// If block is already full, abort
if gp := w.current.gasPool; gp != nil && gp.Gas() < params.TxGas {
continue
Expand Down Expand Up @@ -481,7 +481,7 @@ func (w *worker) commitWorkWithDelay(ctx context.Context, interrupt *int32, noem
tracing.Exec(ctx, "", "worker.prepareWork", func(ctx context.Context, span trace.Span) {
// Set the coinbase if the worker is running or it's required
var coinbase common.Address
if w.isRunning() {
if w.IsRunning() {
if w.coinbase == (common.Address{}) {
log.Error("Refusing to mine without etherbase")
return
Expand Down Expand Up @@ -868,7 +868,7 @@ mainloop:
}
}

if !w.isRunning() && len(coalescedLogs) > 0 {
if !w.IsRunning() && len(coalescedLogs) > 0 {
// We don't push the pendingLogsEvent while we are sealing. The reason is that
// when we are sealing, the worker will regenerate a sealing block every 3 seconds.
// In order to avoid pushing the repeated pendingLog, we disable the pending log pushing.
Expand Down
17 changes: 9 additions & 8 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ func (w *worker) stop() {
}

// isRunning returns an indicator whether worker is running or not.
func (w *worker) isRunning() bool {
func (w *worker) IsRunning() bool {
return w.running.Load()
}

Expand Down Expand Up @@ -589,7 +589,7 @@ func (w *worker) newWorkLoop(ctx context.Context, recommit time.Duration) {
case <-timer.C:
// If sealing is running resubmit a new work cycle periodically to pull in
// higher priced transactions. Disable this overhead for pending blocks.
if w.isRunning() && (w.chainConfig.Clique == nil || w.chainConfig.Clique.Period > 0) {
if w.IsRunning() && (w.chainConfig.Clique == nil || w.chainConfig.Clique.Period > 0) {
// Short circuit if no new transaction arrives.
if w.newTxs.Load() == 0 {
timer.Reset(recommit)
Expand Down Expand Up @@ -684,7 +684,7 @@ func (w *worker) mainLoop(ctx context.Context) {
}
// If our mining block contains less than 2 uncle blocks,
// add the new uncle block if valid and regenerate a mining block.
if w.isRunning() && w.current != nil && len(w.current.uncles) < 2 {
if w.IsRunning() && w.current != nil && len(w.current.uncles) < 2 {
start := time.Now()
if err := w.commitUncle(w.current, ev.Block.Header()); err == nil {
commitErr := w.commit(ctx, w.current.copy(), nil, true, start)
Expand Down Expand Up @@ -714,7 +714,8 @@ func (w *worker) mainLoop(ctx context.Context) {
// Note all transactions received may not be continuous with transactions
// already included in the current sealing block. These transactions will
// be automatically eliminated.
if !w.isRunning() && w.current != nil {
// nolint : nestif
if !w.IsRunning() && w.current != nil {
// If block is already full, abort
if gp := w.current.gasPool; gp != nil && gp.Gas() < params.TxGas {
continue
Expand Down Expand Up @@ -1235,7 +1236,7 @@ mainloop:
}

// nolint:nestif
if EnableMVHashMap && w.isRunning() {
if EnableMVHashMap && w.IsRunning() {
close(chDeps)
depsWg.Wait()

Expand Down Expand Up @@ -1296,7 +1297,7 @@ mainloop:

}

if !w.isRunning() && len(coalescedLogs) > 0 {
if !w.IsRunning() && len(coalescedLogs) > 0 {
// We don't push the pendingLogsEvent while we are sealing. The reason is that
// when we are sealing, the worker will regenerate a sealing block every 3 seconds.
// In order to avoid pushing the repeated pendingLog, we disable the pending log pushing.
Expand Down Expand Up @@ -1710,7 +1711,7 @@ func (w *worker) commitWork(ctx context.Context, interrupt *atomic.Int32, noempt
tracing.Exec(ctx, "", "worker.prepareWork", func(ctx context.Context, span trace.Span) {
// Set the coinbase if the worker is running or it's required
var coinbase common.Address
if w.isRunning() {
if w.IsRunning() {
coinbase = w.etherbase()
if coinbase == (common.Address{}) {
log.Error("Refusing to mine without etherbase")
Expand Down Expand Up @@ -1825,7 +1826,7 @@ func getInterruptTimer(ctx context.Context, work *environment, current *types.Bl
// Note the assumption is held that the mutation is allowed to the passed env, do
// the deep copy first.
func (w *worker) commit(ctx context.Context, env *environment, interval func(), update bool, start time.Time) error {
if w.isRunning() {
if w.IsRunning() {
ctx, span := tracing.StartSpan(ctx, "commit")
defer tracing.EndSpan(span)

Expand Down

0 comments on commit c4e0a5c

Please sign in to comment.