mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-12 06:41:31 +00:00
Merge branch 'master' into wb/abci-process-proposal-synchronize
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -149,7 +148,7 @@ for applications built w/ Cosmos SDK).
|
||||
// Initiate the light client. If the trusted store already has blocks in it, this
|
||||
// will be used else we use the trusted options.
|
||||
c, err := light.NewHTTPClient(
|
||||
context.Background(),
|
||||
cmd.Context(),
|
||||
chainID,
|
||||
light.TrustOptions{
|
||||
Period: trustingPeriod,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
master master
|
||||
v0.33.x v0.33
|
||||
v0.34.x v0.34
|
||||
v0.35.x v0.35
|
||||
|
||||
@@ -1086,6 +1086,8 @@ func (cs *State) handleTxsAvailable(ctx context.Context) {
|
||||
// Enter: +2/3 prevotes any or +2/3 precommits for block or any from (height, round)
|
||||
// NOTE: cs.StartTime was already set for height.
|
||||
func (cs *State) enterNewRound(ctx context.Context, height int64, round int32) {
|
||||
// TODO: remove panics in this function and return an error
|
||||
|
||||
logger := cs.logger.With("height", height, "round", round)
|
||||
|
||||
if cs.Height != height || round < cs.Round || (cs.Round == round && cs.Step != cstypes.RoundStepNewHeight) {
|
||||
@@ -1106,7 +1108,11 @@ func (cs *State) enterNewRound(ctx context.Context, height int64, round int32) {
|
||||
validators := cs.Validators
|
||||
if cs.Round < round {
|
||||
validators = validators.Copy()
|
||||
validators.IncrementProposerPriority(tmmath.SafeSubInt32(round, cs.Round))
|
||||
r, err := tmmath.SafeSubInt32(round, cs.Round)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
validators.IncrementProposerPriority(r)
|
||||
}
|
||||
|
||||
// Setup new round
|
||||
@@ -1126,7 +1132,12 @@ func (cs *State) enterNewRound(ctx context.Context, height int64, round int32) {
|
||||
cs.ProposalBlockParts = nil
|
||||
}
|
||||
|
||||
cs.Votes.SetRound(tmmath.SafeAddInt32(round, 1)) // also track next round (round+1) to allow round-skipping
|
||||
r, err := tmmath.SafeAddInt32(round, 1)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
cs.Votes.SetRound(r) // also track next round (round+1) to allow round-skipping
|
||||
cs.TriggeredTimeoutPrecommit = false
|
||||
|
||||
if err := cs.eventBus.PublishEventNewRound(ctx, cs.NewRoundEvent()); err != nil {
|
||||
|
||||
@@ -85,7 +85,11 @@ func (hvs *HeightVoteSet) Round() int32 {
|
||||
func (hvs *HeightVoteSet) SetRound(round int32) {
|
||||
hvs.mtx.Lock()
|
||||
defer hvs.mtx.Unlock()
|
||||
newRound := tmmath.SafeSubInt32(hvs.round, 1)
|
||||
newRound, err := tmmath.SafeSubInt32(hvs.round, 1)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if hvs.round != 0 && (round < newRound) {
|
||||
panic("SetRound() must increment hvs.round")
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func (env *Environment) Subscribe(ctx context.Context, query string) (*coretypes
|
||||
// Capture the current ID, since it can change in the future.
|
||||
subscriptionID := callInfo.RPCRequest.ID
|
||||
go func() {
|
||||
opctx, opcancel := context.WithCancel(context.Background())
|
||||
opctx, opcancel := context.WithCancel(context.TODO())
|
||||
defer opcancel()
|
||||
|
||||
for {
|
||||
|
||||
@@ -504,8 +504,12 @@ func (store dbStore) LoadValidators(height int64) (*types.ValidatorSet, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
h, err := tmmath.SafeConvertInt32(height - lastStoredHeight)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
vs.IncrementProposerPriority(tmmath.SafeConvertInt32(height - lastStoredHeight)) // mutate
|
||||
vs.IncrementProposerPriority(h) // mutate
|
||||
vi2, err := vs.ToProto()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -9,41 +9,37 @@ var ErrOverflowInt32 = errors.New("int32 overflow")
|
||||
var ErrOverflowUint8 = errors.New("uint8 overflow")
|
||||
var ErrOverflowInt8 = errors.New("int8 overflow")
|
||||
|
||||
// SafeAddInt32 adds two int32 integers
|
||||
// If there is an overflow this will panic
|
||||
func SafeAddInt32(a, b int32) int32 {
|
||||
// SafeAddInt32 adds two int32 integers.
|
||||
func SafeAddInt32(a, b int32) (int32, error) {
|
||||
if b > 0 && (a > math.MaxInt32-b) {
|
||||
panic(ErrOverflowInt32)
|
||||
return 0, ErrOverflowInt32
|
||||
} else if b < 0 && (a < math.MinInt32-b) {
|
||||
panic(ErrOverflowInt32)
|
||||
return 0, ErrOverflowInt32
|
||||
}
|
||||
return a + b
|
||||
return a + b, nil
|
||||
}
|
||||
|
||||
// SafeSubInt32 subtracts two int32 integers
|
||||
// If there is an overflow this will panic
|
||||
func SafeSubInt32(a, b int32) int32 {
|
||||
// SafeSubInt32 subtracts two int32 integers.
|
||||
func SafeSubInt32(a, b int32) (int32, error) {
|
||||
if b > 0 && (a < math.MinInt32+b) {
|
||||
panic(ErrOverflowInt32)
|
||||
return 0, ErrOverflowInt32
|
||||
} else if b < 0 && (a > math.MaxInt32+b) {
|
||||
panic(ErrOverflowInt32)
|
||||
return 0, ErrOverflowInt32
|
||||
}
|
||||
return a - b
|
||||
return a - b, nil
|
||||
}
|
||||
|
||||
// SafeConvertInt32 takes a int and checks if it overflows
|
||||
// If there is an overflow this will panic
|
||||
func SafeConvertInt32(a int64) int32 {
|
||||
// SafeConvertInt32 takes a int and checks if it overflows.
|
||||
func SafeConvertInt32(a int64) (int32, error) {
|
||||
if a > math.MaxInt32 {
|
||||
panic(ErrOverflowInt32)
|
||||
return 0, ErrOverflowInt32
|
||||
} else if a < math.MinInt32 {
|
||||
panic(ErrOverflowInt32)
|
||||
return 0, ErrOverflowInt32
|
||||
}
|
||||
return int32(a)
|
||||
return int32(a), nil
|
||||
}
|
||||
|
||||
// SafeConvertUint8 takes an int64 and checks if it overflows
|
||||
// If there is an overflow it returns an error
|
||||
// SafeConvertUint8 takes an int64 and checks if it overflows.
|
||||
func SafeConvertUint8(a int64) (uint8, error) {
|
||||
if a > math.MaxUint8 {
|
||||
return 0, ErrOverflowUint8
|
||||
@@ -53,8 +49,7 @@ func SafeConvertUint8(a int64) (uint8, error) {
|
||||
return uint8(a), nil
|
||||
}
|
||||
|
||||
// SafeConvertInt8 takes an int64 and checks if it overflows
|
||||
// If there is an overflow it returns an error
|
||||
// SafeConvertInt8 takes an int64 and checks if it overflows.
|
||||
func SafeConvertInt8(a int64) (int8, error) {
|
||||
if a > math.MaxInt8 {
|
||||
return 0, ErrOverflowInt8
|
||||
|
||||
@@ -51,7 +51,7 @@ func testTxEventsSent(ctx context.Context, t *testing.T, broadcastMethod string,
|
||||
}()
|
||||
|
||||
// and wait for confirmation
|
||||
evt, err := client.WaitForOneEvent(c, types.EventTxValue, waitForEventTimeout)
|
||||
evt, err := client.WaitForOneEvent(ctx, c, types.EventTxValue, waitForEventTimeout)
|
||||
require.NoError(t, err)
|
||||
|
||||
// and make sure it has the proper info
|
||||
|
||||
@@ -57,9 +57,9 @@ func WaitForHeight(ctx context.Context, c StatusClient, h int64, waiter Waiter)
|
||||
// when the timeout duration has expired.
|
||||
//
|
||||
// This handles subscribing and unsubscribing under the hood
|
||||
func WaitForOneEvent(c EventsClient, eventValue string, timeout time.Duration) (types.EventData, error) {
|
||||
func WaitForOneEvent(ctx context.Context, c EventsClient, eventValue string, timeout time.Duration) (types.EventData, error) {
|
||||
const subscriber = "helpers"
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||
defer cancel()
|
||||
|
||||
// register for the next event of this type
|
||||
|
||||
@@ -140,7 +140,7 @@ func (w *wsEvents) UnsubscribeAll(ctx context.Context, subscriber string) error
|
||||
func (w *wsEvents) redoSubscriptionsAfter(d time.Duration) {
|
||||
time.Sleep(d)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := context.TODO()
|
||||
|
||||
w.mtx.Lock()
|
||||
defer w.mtx.Unlock()
|
||||
|
||||
@@ -15,10 +15,10 @@ import (
|
||||
rpctest "github.com/tendermint/tendermint/rpc/test"
|
||||
)
|
||||
|
||||
func NodeSuite(t *testing.T, logger log.Logger) (service.Service, *config.Config) {
|
||||
func NodeSuite(ctx context.Context, t *testing.T, logger log.Logger) (service.Service, *config.Config) {
|
||||
t.Helper()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
||||
conf, err := rpctest.CreateConfig(t, t.Name())
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -95,7 +95,7 @@ func TestClientOperations(t *testing.T) {
|
||||
|
||||
logger := log.NewTestingLogger(t)
|
||||
|
||||
_, conf := NodeSuite(t, logger)
|
||||
_, conf := NodeSuite(ctx, t, logger)
|
||||
|
||||
t.Run("NilCustomHTTPClient", func(t *testing.T) {
|
||||
_, err := rpchttp.NewWithClient("http://example.com", nil)
|
||||
@@ -193,7 +193,7 @@ func TestClientMethodCalls(t *testing.T) {
|
||||
defer cancel()
|
||||
logger := log.NewTestingLogger(t)
|
||||
|
||||
n, conf := NodeSuite(t, logger)
|
||||
n, conf := NodeSuite(ctx, t, logger)
|
||||
|
||||
// for broadcast tx tests
|
||||
pool := getMempool(t, n)
|
||||
@@ -471,7 +471,7 @@ func TestClientMethodCalls(t *testing.T) {
|
||||
})
|
||||
t.Run("Events", func(t *testing.T) {
|
||||
t.Run("Header", func(t *testing.T) {
|
||||
evt, err := client.WaitForOneEvent(c, types.EventNewBlockHeaderValue, waitForEventTimeout)
|
||||
evt, err := client.WaitForOneEvent(ctx, c, types.EventNewBlockHeaderValue, waitForEventTimeout)
|
||||
require.NoError(t, err, "%d: %+v", i, err)
|
||||
_, ok := evt.(types.EventDataNewBlockHeader)
|
||||
require.True(t, ok, "%d: %#v", i, evt)
|
||||
@@ -583,7 +583,7 @@ func TestClientMethodCallsAdvanced(t *testing.T) {
|
||||
|
||||
logger := log.NewTestingLogger(t)
|
||||
|
||||
n, conf := NodeSuite(t, logger)
|
||||
n, conf := NodeSuite(ctx, t, logger)
|
||||
pool := getMempool(t, n)
|
||||
|
||||
t.Run("UnconfirmedTxs", func(t *testing.T) {
|
||||
|
||||
@@ -175,7 +175,7 @@ func startLightNode(ctx context.Context, cfg *Config) error {
|
||||
providers := rpcEndpoints(tmcfg.P2P.PersistentPeers)
|
||||
|
||||
c, err := light.NewHTTPClient(
|
||||
context.Background(),
|
||||
ctx,
|
||||
cfg.ChainID,
|
||||
light.TrustOptions{
|
||||
Period: tmcfg.StateSync.TrustPeriod,
|
||||
|
||||
@@ -43,7 +43,7 @@ func Benchmark(ctx context.Context, testnet *e2e.Testnet, benchmarkLength int64)
|
||||
logger.Info("Ending benchmark period", "height", block.Height)
|
||||
|
||||
// fetch a sample of blocks
|
||||
blocks, err := fetchBlockChainSample(testnet, benchmarkLength)
|
||||
blocks, err := fetchBlockChainSample(ctx, testnet, benchmarkLength)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -128,7 +128,7 @@ func (t *testnetStats) String() string {
|
||||
|
||||
// fetchBlockChainSample waits for `benchmarkLength` amount of blocks to pass, fetching
|
||||
// all of the headers for these blocks from an archive node and returning it.
|
||||
func fetchBlockChainSample(testnet *e2e.Testnet, benchmarkLength int64) ([]*types.BlockMeta, error) {
|
||||
func fetchBlockChainSample(ctx context.Context, testnet *e2e.Testnet, benchmarkLength int64) ([]*types.BlockMeta, error) {
|
||||
var blocks []*types.BlockMeta
|
||||
|
||||
// Find the first archive node
|
||||
@@ -139,7 +139,6 @@ func fetchBlockChainSample(testnet *e2e.Testnet, benchmarkLength int64) ([]*type
|
||||
}
|
||||
|
||||
// find the latest height
|
||||
ctx := context.Background()
|
||||
s, err := c.Status(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user