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

feat (rollapp): register balances l2 #1247

Merged
merged 134 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
de9c1cb
temp commit to merge main
Oct 30, 2024
76e3b1a
fork validation and send freeze signal
Oct 30, 2024
b2bf43e
fix tests
Oct 30, 2024
879766c
go lint
Oct 30, 2024
0a7f39b
move test file
Oct 31, 2024
f326c35
add tests
Oct 31, 2024
3893738
put rolllap fields in proto from int64 to uint64
Oct 31, 2024
cdb0cf3
add skip to test
Oct 31, 2024
0283729
add nolint
Oct 31, 2024
300bd48
move nolint
Oct 31, 2024
fccc852
include NewDRS message
Nov 4, 2024
eb8668a
remove commented code
Nov 4, 2024
5e037d4
adjust mock
Nov 5, 2024
c833986
merge main
Nov 5, 2024
ff877ef
update the way we get version
Nov 6, 2024
47903ba
fix faulty drs misconception
Nov 6, 2024
6903b02
add improvement related to fork
Nov 6, 2024
a98a616
bring back monitor fork update
Nov 5, 2024
6ae531b
update code
Nov 6, 2024
51c788d
some comments solved
Nov 7, 2024
8f6618f
update code
Nov 7, 2024
d6cdd1a
comments on fork
Nov 7, 2024
5a49f60
add review changes
Nov 7, 2024
206578a
send revision
Nov 7, 2024
f86dcad
delete instruction
Nov 8, 2024
32dddd9
fix(hardfork): fix tests and update for height 0 (#1207)
srene Nov 8, 2024
8673f57
remove sequencer on instruction
Nov 8, 2024
665d5c5
validate blocks
Nov 8, 2024
fd753cc
batch checking before sending the 2 fork blocks
Nov 8, 2024
16a4003
add some comments
Nov 8, 2024
e629e3e
fix(manager/indexer): pruning fixes (#1147)
srene Nov 7, 2024
e8f0ee3
freeze proposer
srene Nov 9, 2024
a7d7e57
lint fix
srene Nov 9, 2024
9fa63cf
lint test
srene Nov 9, 2024
b150dad
freeze submit loop
srene Nov 9, 2024
88df4b1
race cond fix
srene Nov 10, 2024
2f307c4
fix
srene Nov 10, 2024
cf213d9
revision start height changes
srene Nov 10, 2024
e63d30b
obsolete drs query
srene Nov 10, 2024
e9a1f57
obsolete drs
srene Nov 10, 2024
82aa03d
test fix
srene Nov 10, 2024
65a32fd
lint fix
srene Nov 10, 2024
e14ceb6
fix
srene Nov 10, 2024
f27822e
clear drsversion fork
srene Nov 11, 2024
f24ca4d
merge fix
srene Nov 11, 2024
23e688f
merge fix
srene Nov 11, 2024
658dea0
addressing comments
srene Nov 11, 2024
892ba12
updated hub query proto
srene Nov 11, 2024
d76875f
stop for next height is revision height also for fullnode
srene Nov 11, 2024
b03343d
rollapp query proto
srene Nov 11, 2024
ed21ee9
proto fix
srene Nov 11, 2024
dd744b9
addressing comments
srene Nov 11, 2024
476e0a6
addressing comments
srene Nov 11, 2024
b5827fb
fixme
srene Nov 11, 2024
9441729
fix
srene Nov 11, 2024
2cb5922
fixes consensus msgs
srene Nov 11, 2024
e8ce428
test fix
srene Nov 11, 2024
12ae4dd
fix: consensus msgs serialization
keruch Nov 12, 2024
36ed2fc
fixes
srene Nov 12, 2024
fae5391
remove stop syncing drs upgrade
srene Nov 12, 2024
fb2e64e
exiting loops when freezing
srene Nov 12, 2024
59a92d1
createForkBlocks func
Nov 12, 2024
c34b1f0
Merge branch 'srene/hardfork-fix' of github.com-faulty:dymensionxyz/d…
Nov 12, 2024
f5ba4e0
replace bool by channel
srene Nov 12, 2024
0df4a20
update name of function
Nov 12, 2024
2d2eaa4
move method
Nov 12, 2024
6386502
revision updated
Nov 12, 2024
272c54c
using context to freeze node
srene Nov 12, 2024
0fa99a1
fix
srene Nov 12, 2024
cb16606
merge
srene Nov 12, 2024
35db9a9
freeze update
srene Nov 12, 2024
a299a20
merge
srene Nov 12, 2024
9cfdbd5
freeze refactor
srene Nov 12, 2024
05d58dd
addressing comments
srene Nov 12, 2024
d4a2bab
addressing comments
srene Nov 12, 2024
3eae065
lint fix
srene Nov 12, 2024
45fe640
check againgst prefork drs
srene Nov 13, 2024
90365f6
be more defensive in fork
Nov 13, 2024
90cfb46
Merge branch 'srene/hardfork-fix' of github.com-faulty:dymensionxyz/d…
Nov 13, 2024
67ff0ca
remove unused func
Nov 13, 2024
dbdccfb
send drs upgrade cns mssg in all cases
srene Nov 13, 2024
cbb4b09
lint fix
srene Nov 13, 2024
48da753
instruction exist
Nov 13, 2024
5700cbd
merged
Nov 13, 2024
f20fadc
remove unused function
srene Nov 13, 2024
af24f12
bytes in block hash err
srene Nov 14, 2024
f353a9d
lint fix
srene Nov 14, 2024
db18434
tweaks fixes (#1233)
danwt Nov 15, 2024
3ae0608
drs for ldflag
srene Nov 15, 2024
75a63c9
simplify checkforupdatE
srene Nov 15, 2024
4adfc92
add validation hard fork support and stopping fullnodes syncing when …
srene Nov 16, 2024
e100840
last fixes
Nov 16, 2024
4c9ec0e
Merge branch 'srene/hardfork-fix' of github.com-faulty:dymensionxyz/d…
Nov 16, 2024
5f0f8d1
test fix
srene Nov 16, 2024
2cb5b7a
remove extra delete instruction
srene Nov 16, 2024
4ce2d42
last fixes
Nov 16, 2024
fae0f51
fix nil pointer proposer
srene Nov 17, 2024
8dbc1d8
code refactoring
srene Nov 17, 2024
8be0b14
Merge branch 'srene/hardfork-fix' of github.com-faulty:dymensionxyz/d…
Nov 18, 2024
597c3e2
Merge branch 'srene/hardfork-fix' of github.com-faulty:dymensionxyz/d…
Nov 18, 2024
7d4447b
merge
srene Nov 18, 2024
fcbc31d
rdk dep fix
srene Nov 18, 2024
e8e20c4
update rollback msg
srene Nov 18, 2024
ab32461
comments
srene Nov 18, 2024
6419ab7
fixing tests
srene Nov 18, 2024
fb6745a
lint
srene Nov 18, 2024
526619b
fix ctx
srene Nov 18, 2024
9d3dff0
feat: syncing with changing revisions (#1234)
keruch Nov 18, 2024
e5437bc
refactor some errors
Nov 18, 2024
279838c
some more info
Nov 18, 2024
52a300a
unify errors and include necesary info
Nov 18, 2024
e55a0f6
add comments
Nov 18, 2024
122f0d3
Merge remote-tracking branch 'origin/srene/hardfork-fix' into feat/in…
Nov 18, 2024
e93f448
temp commit
Nov 19, 2024
59dc8b2
Merge remote-tracking branch 'origin/main' into feat/increase-fraud-i…
Nov 19, 2024
d7053d2
refactor due to review
Nov 19, 2024
4340930
Merge remote-tracking branch 'origin/feat/increase-fraud-information'…
Nov 19, 2024
f061882
another update
Nov 19, 2024
0cf5b50
include balances monitor
Nov 20, 2024
e23e7c9
monitor balances gauge configuration
Nov 20, 2024
975db53
remove replace import
Nov 20, 2024
b0a5d96
Merge remote-tracking branch 'origin/main' into feat/register-balance…
Nov 21, 2024
d2a3917
update go mod
Nov 21, 2024
9ceb70a
recreate mocks
Nov 21, 2024
036243a
modify based on review
Nov 22, 2024
efd2eb0
modify based on review
Nov 22, 2024
5b59757
move monitor balances to general path
Nov 22, 2024
5d46ffd
error scope clarity
Nov 22, 2024
340d0e3
implement panic methods
Nov 22, 2024
16ffe54
update code
Nov 22, 2024
f40296b
errs update
Nov 22, 2024
37de170
review changes
Nov 22, 2024
5b374cf
Merge remote-tracking branch 'origin/main' into feat/register-balance…
Nov 22, 2024
2a3248f
fix lint
Nov 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions block/balance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package block

import (
"context"
"fmt"
"strconv"
"sync"
"time"

"github.com/cockroachdb/errors"
"github.com/dymensionxyz/dymint/da"
"github.com/dymensionxyz/dymint/types"
)

const CheckBalancesInterval = 3 * time.Minute

// MonitorBalances checks the balances of the node and updates the gauges for prometheus
func (m *Manager) MonitorBalances(ctx context.Context) error {
ticker := time.NewTicker(CheckBalancesInterval)
defer ticker.Stop()

for {
select {
case <-ctx.Done():
return nil
case <-ticker.C:
m.logger.Info("Checking balances.")
balances, err := m.checkBalances()

if balances.DA != nil {
if amountFloat, errDA := strconv.ParseFloat(balances.DA.Amount.String(), 64); errDA == nil {
types.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)
} else {
m.logger.Error("Parsing SL balance amount", "error", errSL)
}
}

if err != nil {
m.logger.Error("Checking balances", "error", err)
}
}
}
}

type Balances struct {
DA *da.Balance
SL *types.Balance
}

func (m *Manager) checkBalances() (*Balances, error) {
balances := &Balances{}
var wg sync.WaitGroup
wg.Add(2)

var errDA, errSL error

go func() {
defer wg.Done()
balance, err := m.DAClient.GetSignerBalance()
if err != nil {
errDA = fmt.Errorf("get DA signer balance: %w", err)
return
}
balances.DA = &balance
}()

go func() {
defer wg.Done()
balance, err := m.SLClient.GetSignerBalance()
if err != nil {
errSL = fmt.Errorf("get SL signer balance: %w", err)
return
}
balances.SL = &balance
}()

wg.Wait()

errs := errors.Join(errDA, errSL)
if errs != nil {
return balances, fmt.Errorf("errors checking balances: %w", errs)
}

return balances, nil
}
4 changes: 4 additions & 0 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ func (m *Manager) Start(ctx context.Context) error {
return m.MonitorForkUpdateLoop(ctx)
})

uerrors.ErrGroupGoLog(eg, m.logger, func() error {
return m.MonitorBalances(ctx)
})

// run based on the node role
if !amIProposer {
return m.runAsFullNode(ctx, eg)
Expand Down
7 changes: 6 additions & 1 deletion da/avail/avail.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func WithBatchRetryAttempts(attempts uint) da.Option {
}

// Init initializes DataAvailabilityLayerClient instance.
func (c *DataAvailabilityLayerClient) Init(config []byte, pubsubServer *pubsub.Server, kvStore store.KV, logger types.Logger, options ...da.Option) error {
func (c *DataAvailabilityLayerClient) Init(config []byte, pubsubServer *pubsub.Server, _ store.KV, logger types.Logger, options ...da.Option) error {
c.logger = logger
c.synced = make(chan struct{}, 1)

Expand Down Expand Up @@ -442,3 +442,8 @@ func (c *DataAvailabilityLayerClient) getHeightFromHash(hash availtypes.Hash) (u
func (d *DataAvailabilityLayerClient) GetMaxBlobSizeBytes() uint32 {
return maxBlobSize
}

// GetBalance returns the balance for a specific address
func (c *DataAvailabilityLayerClient) GetSignerBalance() (da.Balance, error) {
return da.Balance{}, nil
}
20 changes: 19 additions & 1 deletion da/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func WithSubmitBackoff(c uretry.BackoffConfig) da.Option {
}

// Init initializes DataAvailabilityLayerClient instance.
func (c *DataAvailabilityLayerClient) Init(config []byte, pubsubServer *pubsub.Server, kvStore store.KV, logger types.Logger, options ...da.Option) error {
func (c *DataAvailabilityLayerClient) Init(config []byte, pubsubServer *pubsub.Server, _ store.KV, logger types.Logger, options ...da.Option) error {
c.logger = logger
c.synced = make(chan struct{}, 1)
var err error
Expand Down Expand Up @@ -605,3 +605,21 @@ func (c *DataAvailabilityLayerClient) sync(rpc *openrpc.Client) {
func (d *DataAvailabilityLayerClient) GetMaxBlobSizeBytes() uint32 {
return maxBlobSizeBytes
}

// GetSignerBalance returns the balance for a specific address
func (d *DataAvailabilityLayerClient) GetSignerBalance() (da.Balance, error) {
ctx, cancel := context.WithTimeout(d.ctx, d.config.Timeout)
defer cancel()

balance, err := d.rpc.GetSignerBalance(ctx)
if err != nil {
return da.Balance{}, fmt.Errorf("get balance: %w", err)
}

daBalance := da.Balance{
Amount: balance.Amount,
Denom: balance.Denom,
}

return daBalance, nil
}
12 changes: 9 additions & 3 deletions da/celestia/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/celestiaorg/celestia-openrpc/types/blob"
"github.com/celestiaorg/celestia-openrpc/types/header"
"github.com/celestiaorg/celestia-openrpc/types/share"
"github.com/celestiaorg/celestia-openrpc/types/state"

"github.com/dymensionxyz/dymint/da/celestia/types"
)
Expand Down Expand Up @@ -35,7 +36,7 @@ func (c *OpenRPC) Submit(ctx context.Context, blobs []*blob.Blob, options *blob.
return c.rpc.Blob.Submit(ctx, blobs, options)
}

// Getting proof for submitted blob
// GetProof gets the proof for a specific share commitment.
func (c *OpenRPC) GetProof(ctx context.Context, height uint64, namespace share.Namespace, commitment blob.Commitment) (*blob.Proof, error) {
return c.rpc.Blob.GetProof(ctx, height, namespace, commitment)
}
Expand All @@ -45,12 +46,17 @@ func (c *OpenRPC) Get(ctx context.Context, height uint64, namespace share.Namesp
return c.rpc.Blob.Get(ctx, height, namespace, commitment)
}

// Get extended Celestia headers for a specific height
// GetByHeight gets the header by height
func (c *OpenRPC) GetByHeight(ctx context.Context, height uint64) (*header.ExtendedHeader, error) {
return c.rpc.Header.GetByHeight(ctx, height)
}

// Get extended Celestia headers for a specific height
// Included checks if a blob is included in the chain
func (c *OpenRPC) Included(ctx context.Context, height uint64, namespace share.Namespace, proof *blob.Proof, commitment blob.Commitment) (bool, error) {
return c.rpc.Blob.Included(ctx, height, namespace, proof, commitment)
}

// GetSignerBalance balance for a specific address
func (c *OpenRPC) GetSignerBalance(ctx context.Context) (*state.Balance, error) {
return c.rpc.State.Balance(ctx)
}
4 changes: 4 additions & 0 deletions da/celestia/types/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/celestiaorg/celestia-openrpc/types/blob"
"github.com/celestiaorg/celestia-openrpc/types/header"
"github.com/celestiaorg/celestia-openrpc/types/share"
"github.com/celestiaorg/celestia-openrpc/types/state"
)

type CelestiaRPCClient interface {
Expand All @@ -18,4 +19,7 @@ type CelestiaRPCClient interface {

/* --------------------------------- header --------------------------------- */
GetByHeight(ctx context.Context, height uint64) (*header.ExtendedHeader, error)

/* ---------------------------------- state --------------------------------- */
GetSignerBalance(ctx context.Context) (*state.Balance, error)
}
9 changes: 9 additions & 0 deletions da/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strconv"
"strings"

"cosmossdk.io/math"
"github.com/celestiaorg/celestia-openrpc/types/blob"
"github.com/cometbft/cometbft/crypto/merkle"
"github.com/dymensionxyz/dymint/store"
Expand Down Expand Up @@ -74,6 +75,11 @@ type DASubmitMetaData struct {
Root []byte
}

type Balance struct {
Amount math.Int
Denom string
}

const PathSeparator = "|"

// ToPath converts a DAMetaData to a path.
Expand Down Expand Up @@ -221,6 +227,9 @@ type DataAvailabilityLayerClient interface {

// Returns the maximum allowed blob size in the DA, used to check the max batch size configured
GetMaxBlobSizeBytes() uint32

// GetSignerBalance returns the balance for a specific address
GetSignerBalance() (Balance, error)
}

// BatchRetriever is additional interface that can be implemented by Data Availability Layer Client that is able to retrieve
Expand Down
8 changes: 8 additions & 0 deletions da/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"strconv"

"cosmossdk.io/math"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

Expand Down Expand Up @@ -153,3 +154,10 @@ func (d *DataAvailabilityLayerClient) RetrieveBatches(daMetaData *da.DASubmitMet
Batches: batches,
}
}

func (d *DataAvailabilityLayerClient) GetSignerBalance() (da.Balance, error) {
return da.Balance{
Amount: math.ZeroInt(),
Denom: "adym",
}, nil
}
8 changes: 8 additions & 0 deletions da/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sync/atomic"
"time"

"cosmossdk.io/math"
"github.com/dymensionxyz/dymint/da"
"github.com/dymensionxyz/dymint/store"
"github.com/dymensionxyz/dymint/types"
Expand Down Expand Up @@ -181,3 +182,10 @@ func (m *DataAvailabilityLayerClient) updateDAHeight() {
func (d *DataAvailabilityLayerClient) GetMaxBlobSizeBytes() uint32 {
return maxBlobSize
}

func (m *DataAvailabilityLayerClient) GetSignerBalance() (da.Balance, error) {
return da.Balance{
Amount: math.ZeroInt(),
Denom: "adym",
}, nil
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/centrifuge/go-substrate-rpc-client/v4 v4.0.12
github.com/cosmos/cosmos-sdk v0.46.16
github.com/dgraph-io/badger/v4 v4.3.0
github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20240821081230-b4018b2bac13
github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20241121093220-e0d7ad456fbd
github.com/dymensionxyz/dymension-rdk v1.6.1-0.20241119103059-def6322e4345
github.com/dymensionxyz/gerr-cosmos v1.0.0
github.com/go-kit/kit v0.12.0
Expand Down Expand Up @@ -257,7 +257,7 @@ require (
)

require (
cosmossdk.io/math v1.3.0 // indirect
cosmossdk.io/math v1.3.0
github.com/DataDog/zstd v1.5.5 // indirect
github.com/Jorropo/jsync v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ github.com/dvsekhvalnov/jose2go v1.5.0 h1:3j8ya4Z4kMCwT5nXIKFSV84YS+HdqSSO0VsTQx
github.com/dvsekhvalnov/jose2go v1.5.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
github.com/dymensionxyz/cometbft v0.34.29-0.20241104165035-feade34f8f89 h1:rGkCcx4dWX9mxAUrq7zrdOc44XddMY/nM6kqYTWjerY=
github.com/dymensionxyz/cometbft v0.34.29-0.20241104165035-feade34f8f89/go.mod h1:L9shMfbkZ8B+7JlwANEr+NZbBcn+hBpwdbeYvA5rLCw=
github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20240821081230-b4018b2bac13 h1:u5yeve5jZR6TdRjjR+vYT/8PWKbhwCZxUmAu+/Tnxyg=
github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20240821081230-b4018b2bac13/go.mod h1:jabDQYXrccscSE0fXkh7eQFYPWJCRiuWKonFGObVq6s=
github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20241121093220-e0d7ad456fbd h1:V89QyOFM84o9w0iFdctMU6So8SS/Xt32JWAXGqJduT0=
github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20241121093220-e0d7ad456fbd/go.mod h1:3weqpVj/TqTFpC0LjEB3H+HZSpm7BrQ1QkEg1Ahy6KY=
github.com/dymensionxyz/dymension-rdk v1.6.1-0.20241119103059-def6322e4345 h1:FcHidPgGEHh9ELwodNJkGcHqsG+mdPiGdughzG4W+X8=
github.com/dymensionxyz/dymension-rdk v1.6.1-0.20241119103059-def6322e4345/go.mod h1:y89w1OG4C4aF7yyW8bv9PwV3o1KkCx1hyt34ap04Rnk=
github.com/dymensionxyz/evmos/v12 v12.1.6-dymension-v0.3 h1:vmAdUGUc4rTIiO3Phezr7vGq+0uPDVKSA4WAe8+yl6w=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading