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

fix(rpc): Fix status CatchingUp field updating #971

Merged
merged 13 commits into from
Jul 31, 2024
Merged
5 changes: 4 additions & 1 deletion block/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"fmt"

"github.com/tendermint/tendermint/libs/pubsub"

"github.com/dymensionxyz/dymint/p2p"
"github.com/dymensionxyz/dymint/types"
"github.com/tendermint/tendermint/libs/pubsub"
)

// onNewGossipedBlock will take a block and apply it
Expand All @@ -22,6 +23,8 @@ func (m *Manager) onNewGossipedBlock(event pubsub.Message) {
return
}

m.updateTargetHeight(block.Header.Height)

m.logger.Debug("Received new block via gossip.", "block height", block.Header.Height, "store height", m.State.Height(), "n cachedBlocks", len(m.blockCache))

nextHeight := m.State.NextHeight()
Expand Down
14 changes: 13 additions & 1 deletion block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type Manager struct {
*/
// The last height which was submitted to both sublayers, that we know of. When we produce new batches, we will
// start at this height + 1.
// It is ALSO used by the producer, because the producer needs to check if it can prune blocks and it wont'
// It is ALSO used by the producer, because the producer needs to check if it can prune blocks and it won't
// prune anything that might be submitted in the future. Therefore, it must be atomic.
LastSubmittedHeight atomic.Uint64

Expand All @@ -68,6 +68,9 @@ type Manager struct {
Retriever da.BatchRetriever
// get the next target height to sync local state to
targetSyncHeight diodes.Diode
// TargetHeight holds the value of the current highest block seen from either p2p (probably higher) or the DA
TargetHeight atomic.Uint64

// Cached blocks and commits for applying at future heights. The blocks may not be valid, because
// we can only do full validation in sequential order.
blockCache map[uint64]CachedBlock
Expand Down Expand Up @@ -225,3 +228,12 @@ func (m *Manager) syncBlockManager() error {
m.logger.Info("Synced.", "current height", m.State.Height(), "last submitted height", m.LastSubmittedHeight.Load())
return nil
}

func (m *Manager) updateTargetHeight(h uint64) {
for {
currentHeight := m.TargetHeight.Load()
if m.TargetHeight.CompareAndSwap(currentHeight, max(currentHeight, h)) {
mtsitrin marked this conversation as resolved.
Show resolved Hide resolved
break
}
}
}
3 changes: 2 additions & 1 deletion block/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/libp2p/go-libp2p/core/crypto"

"github.com/dymensionxyz/dymint/block"
"github.com/dymensionxyz/dymint/p2p"
"github.com/dymensionxyz/dymint/settlement"
"github.com/dymensionxyz/dymint/testutil"
"github.com/dymensionxyz/dymint/types"
"github.com/libp2p/go-libp2p/core/crypto"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
Expand Down
5 changes: 3 additions & 2 deletions block/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
"sync/atomic"
"time"

"github.com/dymensionxyz/gerr-cosmos/gerrc"
"golang.org/x/sync/errgroup"

"github.com/dymensionxyz/dymint/da"
"github.com/dymensionxyz/dymint/types"
uchannel "github.com/dymensionxyz/dymint/utils/channel"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
"golang.org/x/sync/errgroup"
)

// SubmitLoop is the main loop for submitting blocks to the DA and SL layers.
Expand Down
1 change: 1 addition & 0 deletions block/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (m *Manager) SyncToTargetHeightLoop(ctx context.Context) (err error) {
continue
}
types.RollappHubHeightGauge.Set(float64(h))
m.updateTargetHeight(h)
m.targetSyncHeight.Set(diodes.GenericDataType(&h))
m.logger.Info("Set new target sync height", "height", h)
case <-subscription.Cancelled():
Expand Down
9 changes: 3 additions & 6 deletions rpc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ import (
"sort"
"time"

"github.com/dymensionxyz/dymint/types"

"github.com/dymensionxyz/dymint/version"

sdkerrors "cosmossdk.io/errors"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/config"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
Expand All @@ -29,6 +24,8 @@ import (

"github.com/dymensionxyz/dymint/mempool"
"github.com/dymensionxyz/dymint/node"
"github.com/dymensionxyz/dymint/types"
"github.com/dymensionxyz/dymint/version"
)

const (
Expand Down Expand Up @@ -750,13 +747,13 @@ func (c *Client) Status(ctx context.Context) (*ctypes.ResultStatus, error) {
LatestAppHash: latestAppHash[:],
LatestBlockHeight: int64(latestHeight),
LatestBlockTime: time.Unix(0, int64(latestBlockTimeNano)),
CatchingUp: c.node.BlockManager.TargetHeight.Load() > latestHeight,
Copy link
Contributor

Choose a reason for hiding this comment

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

u need to set TargetHeight also in syncBlockManager , currnetly u made it event based only

Copy link
Contributor

Choose a reason for hiding this comment

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

this field needs a docstring as well IMO
the other ones are obvious and fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix pushed

// TODO(tzdybal): add missing fields
// EarliestBlockHash: earliestBlockHash,
// EarliestAppHash: earliestAppHash,
// EarliestBlockHeight: earliestBloc
// kHeight,
// EarliestBlockTime: time.Unix(0, earliestBlockTimeNano),
// CatchingUp: env.ConsensusReactor.WaitSync(),
},
// TODO(ItzhakBokris): update ValidatorInfo fields
ValidatorInfo: ctypes.ValidatorInfo{
Expand Down
Loading