Skip to content

Commit

Permalink
Merge branch 'main' into chore/avail_todos
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin committed Jan 13, 2025
2 parents 03d1422 + bd2214e commit c536e9b
Show file tree
Hide file tree
Showing 30 changed files with 342 additions and 250 deletions.
34 changes: 4 additions & 30 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,12 @@ jobs:
uses: dymensionxyz/rollapp-wasm/.github/workflows/build_image_with_dymint.yml@main
with:
commit_hash: ${{ github.sha }}

combine-artifacts:
needs:
- build-rollapp-evm
- build-rollapp-wasm
runs-on: ubuntu-latest
steps:
- name: Download RollApp EVM artifact
uses: actions/download-artifact@v3
with:
name: rollapp-evm
path: /tmp

- name: Download RollApp WASM artifact
uses: actions/download-artifact@v3
with:
name: rollapp-wasm
path: /tmp

- name: Combine Images into e2e.tar
run: |
tar -cf /tmp/e2e.tar rollapp-evm.tar rollapp-wasm.tar
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: e2e
path: /tmp/e2e.tar

e2e-tests:
needs: combine-artifacts
uses: dymensionxyz/e2e-tests/.github/workflows/e2e-test-workflow-call.yml@main
needs:
- build-rollapp-evm
- build-rollapp-wasm
uses: dymensionxyz/e2e-tests/.github/workflows/e2e-test-dymint-workflow-call.yml@main
with:
rollapp_evm_ci: "e2e"
rollapp_wasm_ci: "e2e"
5 changes: 3 additions & 2 deletions block/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/cockroachdb/errors"
"github.com/dymensionxyz/dymint/da"
"github.com/dymensionxyz/dymint/types"
"github.com/dymensionxyz/dymint/types/metrics"
)

const CheckBalancesInterval = 3 * time.Minute
Expand All @@ -29,15 +30,15 @@ func (m *Manager) MonitorBalances(ctx context.Context) error {

if balances.DA != nil {
if amountFloat, errDA := strconv.ParseFloat(balances.DA.Amount.String(), 64); errDA == nil {
types.DaLayerBalanceGauge.Set(amountFloat)
metrics.DaLayerBalanceGauge.Set(amountFloat)
} else {
m.logger.Error("Parsing DA balance amount", "error", errDA)
}
}

if balances.SL != nil {
if amountFloat, errSL := strconv.ParseFloat(balances.SL.Amount.String(), 64); errSL == nil {
types.HubLayerBalanceGauge.Set(amountFloat)
metrics.HubLayerBalanceGauge.Set(amountFloat)
} else {
m.logger.Error("Parsing SL balance amount", "error", errSL)
}
Expand Down
11 changes: 7 additions & 4 deletions block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
errorsmod "cosmossdk.io/errors"

"github.com/dymensionxyz/dymint/types"
"github.com/dymensionxyz/dymint/types/metrics"
)

// applyBlockWithFraudHandling calls applyBlock and validateBlockBeforeApply with fraud handling.
Expand Down Expand Up @@ -56,8 +57,6 @@ func (m *Manager) applyBlock(block *types.Block, commit *types.Commit, blockMeta
return types.ErrInvalidBlockHeight
}

types.SetLastAppliedBlockSource(blockMetaData.Source.String())

m.logger.Debug("Applying block", "height", block.Header.Height, "source", blockMetaData.Source.String())

// Check if the app's last block height is the same as the currently produced block height
Expand Down Expand Up @@ -181,8 +180,6 @@ func (m *Manager) applyBlock(block *types.Block, commit *types.Commit, blockMeta
return fmt.Errorf("commit state: %w", err)
}

types.RollappHeightGauge.Set(float64(block.Header.Height))

m.blockCache.Delete(block.Header.Height)

// validate whether configuration params and rollapp consensus params keep in line, after rollapp params are updated from the responses received in the block execution
Expand All @@ -199,6 +196,12 @@ func (m *Manager) applyBlock(block *types.Block, commit *types.Commit, blockMeta
panic("I'm the new Proposer now. restarting as a proposer")
}

// update metrics
metrics.RollappHeightGauge.Set(float64(block.Header.Height))
metrics.RollappBlockSizeBytesGauge.Set(float64(block.SizeBytes()))
metrics.RollappBlockSizeTxsGauge.Set(float64(len(block.Data.Txs)))
metrics.SetLastAppliedBlockSource(blockMetaData.Source.String())

return nil
}

Expand Down
5 changes: 3 additions & 2 deletions block/block_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package block

import (
"github.com/dymensionxyz/dymint/types"
"github.com/dymensionxyz/dymint/types/metrics"
)

type Cache struct {
Expand All @@ -11,12 +12,12 @@ type Cache struct {

func (m *Cache) Add(h uint64, b *types.Block, c *types.Commit, source types.BlockSource) {
m.cache[h] = types.CachedBlock{Block: b, Commit: c, Source: source}
types.BlockCacheSizeGauge.Set(float64(m.Size()))
metrics.BlockCacheSizeGauge.Set(float64(m.Size()))
}

func (m *Cache) Delete(h uint64) {
delete(m.cache, h)
types.BlockCacheSizeGauge.Set(float64(m.Size()))
metrics.BlockCacheSizeGauge.Set(float64(m.Size()))
}

func (m *Cache) Get(h uint64) (types.CachedBlock, bool) {
Expand Down
2 changes: 1 addition & 1 deletion block/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (e *Executor) CreateBlock(
}

block.Header.SetDymHeader(types.MakeDymHeader(block.Data.ConsensusMessages))
copy(block.Header.LastCommitHash[:], types.GetLastCommitHash(lastCommit, &block.Header))
copy(block.Header.LastCommitHash[:], types.GetLastCommitHash(lastCommit))
copy(block.Header.DataHash[:], types.GetDataHash(block))
copy(block.Header.SequencerHash[:], state.GetProposerHash())
copy(block.Header.NextSequencersHash[:], nextSeqHash[:])
Expand Down
5 changes: 5 additions & 0 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ func (m *Manager) Start(ctx context.Context) error {
})

// Start the settlement sync loop in the background
// TODO: should be called for fullnode only? it's triggered by p2p callback anyhow
uerrors.ErrGroupGoLog(eg, m.logger, func() error {
return m.SettlementSyncLoop(ctx)
})
Expand Down Expand Up @@ -348,6 +349,10 @@ func (m *Manager) GetProposerPubKey() tmcrypto.PubKey {
return m.State.GetProposerPubKey()
}

func (m *Manager) SafeProposerPubKey() (tmcrypto.PubKey, error) {
return m.State.SafeProposerPubKey()
}

func (m *Manager) GetRevision() uint64 {
return m.State.GetRevision()
}
Expand Down
3 changes: 2 additions & 1 deletion block/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

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

Expand Down Expand Up @@ -49,7 +50,7 @@ func (m *Manager) OnReceivedBlock(event pubsub.Message) {
}

m.UpdateTargetHeight(height)
types.LastReceivedP2PHeightGauge.Set(float64(height))
metrics.LastReceivedP2PHeightGauge.Set(float64(height))

m.logger.Debug("Received new block from p2p.", "block height", height, "source", source.String(), "store height", m.State.Height(), "n cachedBlocks", m.blockCache.Size())
m.blockCache.Add(height, &block, &commit, source)
Expand Down
2 changes: 0 additions & 2 deletions block/produce.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,6 @@ func (m *Manager) produceBlock(opts ProduceBlockOptions) (*types.Block, *types.C
}

m.logger.Info("Block created.", "height", newHeight, "num_tx", len(block.Data.Txs), "size", block.SizeBytes()+commit.SizeBytes())
types.RollappBlockSizeBytesGauge.Set(float64(len(block.Data.Txs)))
types.RollappBlockSizeTxsGauge.Set(float64(len(block.Data.Txs)))
return block, commit, nil
}

Expand Down
7 changes: 5 additions & 2 deletions block/slvalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/dymensionxyz/dymint/da"
"github.com/dymensionxyz/dymint/settlement"
"github.com/dymensionxyz/dymint/types"
"github.com/dymensionxyz/dymint/types/metrics"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
)

Expand Down Expand Up @@ -95,7 +96,6 @@ func (v *SettlementValidator) ValidateStateUpdate(batch *settlement.ResultRetrie
daBlocks := []*types.Block{}
for _, batch := range daBatch.Batches {
daBlocks = append(daBlocks, batch.Blocks...)
types.LastReceivedDAHeightGauge.Set(float64(batch.EndHeight()))
}

// validate DA blocks against the state update
Expand Down Expand Up @@ -218,10 +218,13 @@ func (v *SettlementValidator) UpdateLastValidatedHeight(height uint64) {
for {
curr := v.lastValidatedHeight.Load()
if v.lastValidatedHeight.CompareAndSwap(curr, max(curr, height)) {
_, err := v.blockManager.Store.SaveValidationHeight(v.GetLastValidatedHeight(), nil)
h := v.lastValidatedHeight.Load()
_, err := v.blockManager.Store.SaveValidationHeight(h, nil)
if err != nil {
v.logger.Error("update validation height: %w", err)
}

metrics.LastValidatedHeight.Set(float64(h))
break
}
}
Expand Down
28 changes: 16 additions & 12 deletions block/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/dymensionxyz/dymint/da"
"github.com/dymensionxyz/dymint/settlement"
"github.com/dymensionxyz/dymint/types"
"github.com/dymensionxyz/dymint/types/metrics"
uchannel "github.com/dymensionxyz/dymint/utils/channel"
)

Expand Down Expand Up @@ -99,6 +100,7 @@ func SubmitLoopInner(
}

pending := pendingBytes.Load()
UpdateBatchSubmissionGauges(pending, unsubmittedBlocksNum(), batchSkewTime())

// while there are accumulated blocks, create and submit batches!!
for {
Expand All @@ -108,8 +110,6 @@ func SubmitLoopInner(
lastSubmissionIsRecent := isLastBatchRecent(maxBatchSubmitTime)
maxDataNotExceeded := pending <= maxBatchSubmitBytes

UpdateBatchSubmissionGauges(pending, unsubmittedBlocksNum(), batchSkewTime())

if done || nothingToSubmit || (lastSubmissionIsRecent && maxDataNotExceeded) {
break
}
Expand All @@ -131,10 +131,13 @@ func SubmitLoopInner(
}
pending = uint64(unsubmittedBlocksBytes()) //nolint:gosec // bytes size is always positive
// after new batch submitted we check the skew time to wake up 'trigger' thread and restart block production
if batchSkewTime() < maxSkewTime {
skewTime := batchSkewTime()
if skewTime < maxSkewTime {
trigger.Nudge()
}
logger.Debug("Submitted a batch to both sub-layers.", "n bytes consumed from pending", nConsumed, "pending after", pending, "skew time", batchSkewTime())
UpdateBatchSubmissionGauges(pending, unsubmittedBlocksNum(), skewTime)

logger.Debug("Submitted a batch to both sub-layers.", "n bytes consumed from pending", nConsumed, "pending after", pending, "skew time", skewTime)
}
// update pendingBytes with non submitted block bytes after all pending batches have been submitted
pendingBytes.Store(pending)
Expand Down Expand Up @@ -179,13 +182,12 @@ func (m *Manager) CreateAndSubmitBatch(maxSizeBytes uint64, lastBatch bool) (*ty
if lastBatch && b.EndHeight() == endHeightInclusive {
b.LastBatch = true
}

m.logger.Info("Created batch.", "start height", startHeight, "end height", endHeightInclusive, "size", b.SizeBytes(), "last batch", b.LastBatch)
types.LastBatchSubmittedBytes.Set(float64(b.SizeBytes()))

if err := m.SubmitBatch(b); err != nil {
return nil, fmt.Errorf("submit batch: %w", err)
}

return b, nil
}

Expand Down Expand Up @@ -256,12 +258,14 @@ func (m *Manager) SubmitBatch(batch *types.Batch) error {

m.logger.Info("Submitted batch to SL.", "start height", batch.StartHeight(), "end height", batch.EndHeight())

types.RollappHubHeightGauge.Set(float64(batch.EndHeight()))
m.LastSettlementHeight.Store(batch.EndHeight())

// update last submitted block time with batch last block (used to calculate max skew time)
m.LastSettlementHeight.Store(batch.EndHeight())
m.LastSubmissionTime.Store(time.Now().UTC().UnixNano())

// update metrics
metrics.RollappHubHeightGauge.Set(float64(batch.EndHeight()))
metrics.LastBatchSubmittedBytes.Set(float64(batch.SizeBytes()))

return err
}

Expand Down Expand Up @@ -372,7 +376,7 @@ func (m *Manager) isLastBatchRecent(maxBatchSubmitTime time.Duration) bool {
}

func UpdateBatchSubmissionGauges(skewBytes uint64, skewBlocks uint64, skewTime time.Duration) {
types.RollappPendingSubmissionsSkewBytes.Set(float64(skewBytes))
types.RollappPendingSubmissionsSkewBlocks.Set(float64(skewBlocks))
types.RollappPendingSubmissionsSkewTimeMinutes.Set(float64(skewTime.Minutes()))
metrics.RollappPendingSubmissionsBytes.Set(float64(skewBytes))
metrics.RollappPendingSubmissionsBlocks.Set(float64(skewBlocks))
metrics.RollappPendingSubmissionsSkewTimeMinutes.Set(float64(skewTime.Minutes()))
}
2 changes: 2 additions & 0 deletions block/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"

"github.com/dymensionxyz/dymint/da"
"github.com/dymensionxyz/dymint/types/metrics"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
"github.com/tendermint/tendermint/libs/pubsub"

Expand All @@ -21,6 +22,7 @@ func (m *Manager) onNewStateUpdate(event pubsub.Message) {
}

// Update heights based on state update end height
metrics.RollappHubHeightGauge.Set(float64(eventData.EndHeight))
m.LastSettlementHeight.Store(eventData.EndHeight)

// Update sequencers list from SL
Expand Down
5 changes: 3 additions & 2 deletions da/avail/avail.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/dymensionxyz/dymint/da"
"github.com/dymensionxyz/dymint/store"
"github.com/dymensionxyz/dymint/types/metrics"
pb "github.com/dymensionxyz/dymint/types/pb/dymint"
)

Expand Down Expand Up @@ -272,7 +273,7 @@ func (c *DataAvailabilityLayerClient) submitBatchLoop(dataBlob []byte) da.Result
var err error
daBlockHeight, err = c.broadcastTx(dataBlob)
if err != nil {
types.RollappConsecutiveFailedDASubmission.Inc()
metrics.RollappConsecutiveFailedDASubmission.Inc()
c.logger.Error("broadcasting batch", "error", err)
if errors.Is(err, da.ErrTxBroadcastConfigError) {
err = retry.Unrecoverable(err)
Expand Down Expand Up @@ -303,7 +304,7 @@ func (c *DataAvailabilityLayerClient) submitBatchLoop(dataBlob []byte) da.Result
c.logger.Error(err.Error())
continue
}
types.RollappConsecutiveFailedDASubmission.Set(0)
metrics.RollappConsecutiveFailedDASubmission.Set(0)

c.logger.Debug("Successfully submitted batch.")
return da.ResultSubmitBatch{
Expand Down
9 changes: 5 additions & 4 deletions da/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
celtypes "github.com/dymensionxyz/dymint/da/celestia/types"
"github.com/dymensionxyz/dymint/store"
"github.com/dymensionxyz/dymint/types"
"github.com/dymensionxyz/dymint/types/metrics"
pb "github.com/dymensionxyz/dymint/types/pb/dymint"
uretry "github.com/dymensionxyz/dymint/utils/retry"
)
Expand Down Expand Up @@ -90,7 +91,7 @@ func (c *DataAvailabilityLayerClient) Init(config []byte, pubsubServer *pubsub.S
apply(c)
}

types.RollappConsecutiveFailedDASubmission.Set(0)
metrics.RollappConsecutiveFailedDASubmission.Set(0)

return nil
}
Expand Down Expand Up @@ -216,7 +217,7 @@ func (c *DataAvailabilityLayerClient) SubmitBatch(batch *types.Batch) da.ResultS

if err != nil {
c.logger.Error("Submit blob.", "error", err)
types.RollappConsecutiveFailedDASubmission.Inc()
metrics.RollappConsecutiveFailedDASubmission.Inc()
backoff.Sleep()
continue
}
Expand All @@ -233,7 +234,7 @@ func (c *DataAvailabilityLayerClient) SubmitBatch(batch *types.Batch) da.ResultS
result := c.CheckBatchAvailability(daMetaData)
if result.Code != da.StatusSuccess {
c.logger.Error("Check batch availability: submitted batch but did not get availability success status.", "error", err)
types.RollappConsecutiveFailedDASubmission.Inc()
metrics.RollappConsecutiveFailedDASubmission.Inc()
backoff.Sleep()
continue
}
Expand All @@ -243,7 +244,7 @@ func (c *DataAvailabilityLayerClient) SubmitBatch(batch *types.Batch) da.ResultS

c.logger.Debug("Blob availability check passed successfully.")

types.RollappConsecutiveFailedDASubmission.Set(0)
metrics.RollappConsecutiveFailedDASubmission.Set(0)
return da.ResultSubmitBatch{
BaseResult: da.BaseResult{
Code: da.StatusSuccess,
Expand Down
Loading

0 comments on commit c536e9b

Please sign in to comment.