Skip to content

Commit

Permalink
feat: add config params (#38)
Browse files Browse the repository at this point in the history
* add config params

* fix

* update config params

* fix avail config

* fix and refactor relayer

* fix lint
  • Loading branch information
PrathyushaLakkireddy authored Sep 19, 2024
1 parent 6ab8d2b commit 3ea06db
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 217 deletions.
25 changes: 8 additions & 17 deletions chainclient/broadcast_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,25 @@ import (
"github.com/vitwit/avail-da-module/types"
)

func GetBinPath() string {
func GetBinPath(daemon string) string {
homeDir, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
}

availdHomePath := filepath.Join(homeDir, ".availsdk")
availdHomePath := filepath.Join(homeDir, daemon)
return availdHomePath
}

func ExecuteTX(ctx sdk.Context, msg types.MsgUpdateBlobStatusRequest, cdc codec.BinaryCodec) error {
func ExecuteTX(ctx sdk.Context, msg types.MsgUpdateBlobStatusRequest, cdc codec.BinaryCodec, config types.AvailConfiguration, nodeDir string) error {
// Define keyring and RPC client configuration

// homePath := "/home/vitwit/.availsdk"
homePath := GetBinPath()
key := os.Getenv("KEY")
keyName := key

if keyName == "" {
keyName = "alice"
}

rpcAddress := "http://localhost:26657"
// homePath := "/home/vitwit/.simapp"
homePath := GetBinPath(nodeDir)
keyName := config.ValidatorKey
rpcAddress := config.CosmosNodeRPC

// Create a keyring
kr, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, homePath, os.Stdin, cdc.(codec.Codec))
kr, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, homePath, os.Stdin, cdc.(codec.Codec)) // TODO : update keyring backend type
if err != nil {
return fmt.Errorf("error creating keyring: %w", err)
}
Expand Down Expand Up @@ -74,8 +67,6 @@ func ExecuteTX(ctx sdk.Context, msg types.MsgUpdateBlobStatusRequest, cdc codec.
return fmt.Errorf("error retrieving account: %w", err)
}

fmt.Println("account details......", account.GetAccountNumber(), account.GetSequence())

// Set the correct account number and sequence
factory := NewFactory(clientCtx).
WithAccountNumber(account.GetAccountNumber()).
Expand Down
6 changes: 3 additions & 3 deletions keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ func (k *Keeper) PreBlocker(ctx sdk.Context, req *abci.RequestFinalizeBlock) err
return nil
}

// Calculate pending range of blocks to post data
provenHeight := k.GetProvenHeightFromStore(ctx)
fromHeight := provenHeight + 1
endHeight := min(fromHeight+uint64(k.MaxBlocksForBlob), uint64(ctx.BlockHeight())) // exclusive i.e [fromHeight, endHeight)
// Calculate pending range of blocks to post data
endHeight := min(fromHeight+k.relayer.AvailConfig.MaxBlobBlocks, uint64(ctx.BlockHeight())) // exclusive i.e [fromHeight, endHeight)

sdkCtx := sdk.UnwrapSDKContext(ctx)
ok := k.SetBlobStatusPending(sdkCtx, fromHeight, endHeight-1)
Expand All @@ -136,7 +136,7 @@ func (k *Keeper) IsValidBlockToPostTODA(height uint64) bool {
return false
}

if (height-1)%k.PublishToAvailBlockInterval != 0 {
if (height-1)%k.relayer.AvailConfig.PublishBlobInterval != 0 {
return false
}

Expand Down
22 changes: 8 additions & 14 deletions keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package keeper
import (
"cosmossdk.io/collections"
storetypes "cosmossdk.io/core/store"
"cosmossdk.io/log"
storetypes2 "cosmossdk.io/store/types"
upgradekeeper "cosmossdk.io/x/upgrade/keeper"
"github.com/cosmos/cosmos-sdk/codec"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/cobra"
availblob1 "github.com/vitwit/avail-da-module"
Expand All @@ -29,11 +31,6 @@ type Keeper struct {

cdc codec.BinaryCodec

PublishToAvailBlockInterval uint64
MaxBlocksForBlob uint
VotingInterval uint64
appID int

unprovenBlocks map[int64][]byte

proposerAddress []byte
Expand All @@ -45,7 +42,9 @@ func NewKeeper(
storeService storetypes.KVStoreService,
uk *upgradekeeper.Keeper,
key storetypes2.StoreKey,
appID int,
_ servertypes.AppOptions,
_ log.Logger,
relayer *relayer.Relayer,
) *Keeper {
sb := collections.NewSchemaBuilder(storeService)

Expand All @@ -60,14 +59,9 @@ func NewKeeper(

storeKey: key,

cdc: cdc,

appID: appID,

unprovenBlocks: make(map[int64][]byte),
MaxBlocksForBlob: 20, // Todo: call this from app.go, later change to params
PublishToAvailBlockInterval: 5, // Todo: call this from app.go, later change to params
VotingInterval: 5,
cdc: cdc,
unprovenBlocks: make(map[int64][]byte),
relayer: relayer,
}
}

Expand Down
2 changes: 1 addition & 1 deletion keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s msgServer) UpdateBlobStatus(ctx context.Context, req *types.MsgUpdateBlo
currentHeight := sdkCtx.BlockHeight()
UpdateAvailHeight(sdkCtx, store, req.AvailHeight) // updates avail height at which the blocks got submitted to DA
lastVotingEndHeight := s.k.GetVotingEndHeightFromStore(sdkCtx, false)
UpdateVotingEndHeight(sdkCtx, store, uint64(currentHeight)+s.k.VotingInterval, false)
UpdateVotingEndHeight(sdkCtx, store, uint64(currentHeight)+s.k.relayer.AvailConfig.VoteInterval, false)
UpdateVotingEndHeight(sdkCtx, store, lastVotingEndHeight, true)
}

Expand Down
2 changes: 1 addition & 1 deletion keeper/vote_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (h *VoteExtHandler) ExtendVoteHandler() sdk.ExtendVoteHandler {
return abciResponseVoteExt, nil
}

ok, err := h.Keeper.relayer.IsDataAvailable(ctx, from, end, availHeight, "http://localhost:8000") // TODO: read light client url from config
ok, err := h.Keeper.relayer.IsDataAvailable(ctx, from, end, availHeight, h.Keeper.relayer.AvailConfig.LightClientURL) // TODO: read light client url from config
if ok {
h.logger.Info("submitted data to Avail verified successfully at",
"block_height", availHeight,
Expand Down
47 changes: 0 additions & 47 deletions relayer/avail/codec.go

This file was deleted.

6 changes: 4 additions & 2 deletions relayer/availclient.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package relayer

import "github.com/vitwit/avail-da-module/types"

// AvailClient is the client that handles data submission
type AvailClient struct {
config AvailConfig
config types.AvailConfiguration
}

// NewAvailClient initializes a new AvailClient
func NewAvailClient(config AvailConfig) (*AvailClient, error) {
func NewAvailClient(config types.AvailConfiguration) (*AvailClient, error) {
// api, err := gsrpc.NewSubstrateAPI(config.AppRpcURL)
// if err != nil {
// return nil, fmt.Errorf("cannot create api:%w", err)
Expand Down
85 changes: 0 additions & 85 deletions relayer/config.go

This file was deleted.

14 changes: 7 additions & 7 deletions relayer/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ func (r *Relayer) ProposePostNextBlocks(ctx sdk.Context, provenHeight int64) []i
}

// only publish new blocks on interval
if (height-1)%int64(r.availPublishBlockInterval) != 0 {
if (height-1)%int64(r.AvailConfig.PublishBlobInterval) != 0 {
return nil
}

var blocks []int64
for block := height - int64(r.availPublishBlockInterval); block < height; block++ {
for block := height - int64(r.AvailConfig.PublishBlobInterval); block < height; block++ {
// this could be false after a genesis restart
if block > provenHeight {
blocks = append(blocks, block)
Expand Down Expand Up @@ -80,12 +80,12 @@ func (r *Relayer) postBlocks(ctx sdk.Context, blocks []int64, cdc codec.BinaryCo

bb := r.GetBlocksDataFromLocal(ctx, blocks)

blockInfo, err := r.SubmitDataToAvailClient(r.rpcClient.config.Seed, r.rpcClient.config.AppID, bb, blocks, r.rpcClient.config.LightClientURL)
blockInfo, err := r.SubmitDataToAvailClient(r.AvailConfig.Seed, r.AvailConfig.AppID, bb, blocks, r.AvailConfig.LightClientURL)
if err != nil {
r.logger.Error("Error while submitting block(s) to Avail DA",
"height_start", blocks[0],
"height_end", blocks[len(blocks)-1],
"appID", strconv.Itoa(r.rpcClient.config.AppID),
"appID", strconv.Itoa(r.AvailConfig.AppID),
)

// execute tx about failure submission
Expand All @@ -97,7 +97,7 @@ func (r *Relayer) postBlocks(ctx sdk.Context, blocks []int64, cdc codec.BinaryCo
},
// AvailHeight: uint64(blockInfo.BlockNumber),
IsSuccess: false,
}, cdc)
}, cdc, r.AvailConfig, r.NodeDir)
if err != nil {
fmt.Println("error while submitting tx...", err)
}
Expand All @@ -116,8 +116,8 @@ func (r *Relayer) postBlocks(ctx sdk.Context, blocks []int64, cdc codec.BinaryCo
IsSuccess: true,
}

// TODO : execute tx about successful submission
err = dacli.ExecuteTX(ctx, msg, cdc)
// execute tx about successful submission
err = dacli.ExecuteTX(ctx, msg, cdc, r.AvailConfig, r.NodeDir)
if err != nil {
fmt.Println("error while submitting tx...", err)
}
Expand Down
Loading

0 comments on commit 3ea06db

Please sign in to comment.