Skip to content

Commit

Permalink
Merge pull request #3672 from oasisprotocol/yawning/fix/3669
Browse files Browse the repository at this point in the history
go/consensus/tendermint/abci/mux: Reject early EstimateGas calls
  • Loading branch information
Yawning authored Feb 2, 2021
2 parents fc59330 + 00706d2 commit f1d17e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .changelog/3669.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
go/consensus/tendermint/abci/mux: Reject early EstimateGas calls

With the new beacon, EstimateGas will not work till either InitChain or
BeginBlock have been called successfully at least once.
15 changes: 13 additions & 2 deletions go/consensus/tendermint/abci/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"math"
"sort"
"sync"
"sync/atomic"
"time"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -39,6 +40,8 @@ const (

metricsUpdateInterval = 10 * time.Second

blockHeightInvalid = -1

// LogEventABCIStateSyncComplete is a log event value that signals an ABCI state syncing
// completed event.
LogEventABCIStateSyncComplete = "tendermint/abci/state_sync_complete"
Expand Down Expand Up @@ -376,7 +379,9 @@ func (mux *abciMux) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginB
if mux.lastBeginBlock == blockHeight {
panic("mux: redundant BeginBlock")
}
mux.lastBeginBlock = blockHeight
defer func() {
atomic.StoreInt64(&mux.lastBeginBlock, blockHeight)
}()
mux.currentTime = req.Header.Time

params := mux.state.ConsensusParameters()
Expand Down Expand Up @@ -574,6 +579,12 @@ func (mux *abciMux) EstimateGas(caller signature.PublicKey, tx *transaction.Tran
return 0, consensus.ErrInvalidArgument
}

// Certain modules, in particular the beacon require InitChain or BeginBlock
// to have completed before initialization is complete.
if atomic.LoadInt64(&mux.lastBeginBlock) == blockHeightInvalid {
return 0, consensus.ErrNoCommittedBlocks
}

// As opposed to other transaction dispatch entry points (CheckTx/DeliverTx), this method can
// be called in parallel to the consensus layer and to other invocations.
//
Expand Down Expand Up @@ -1052,7 +1063,7 @@ func newABCIMux(ctx context.Context, upgrader upgrade.Backend, cfg *ApplicationC
state: state,
appsByName: make(map[string]api.Application),
appsByMethod: make(map[transaction.MethodName]api.Application),
lastBeginBlock: -1,
lastBeginBlock: blockHeightInvalid,
}

mux.logger.Debug("ABCI multiplexer initialized",
Expand Down

0 comments on commit f1d17e9

Please sign in to comment.