Skip to content

Commit

Permalink
load genesis state
Browse files Browse the repository at this point in the history
  • Loading branch information
kstoykov committed Sep 16, 2021
1 parent 0b68110 commit c2f4158
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
17 changes: 17 additions & 0 deletions local-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ADDRESS_PREFIX="cudos"
FEES="100acudos"
GRPC="http://localhost:9090"
ETHRPC="http://104.198.157.197:8545"
CONTRACT_ADDR="0x9fdE6D55dDa637806DbF016a03B6970613630333"
COSMOS_ORCH_MNEMONIC="pencil spirit also middle brave celery obtain merge hurt rocket slice damp account actor fire first science organ charge ring vessel square extra general"
ETH_PRIV_KEY_HEX="ed1eb2a53e4f15d2d60009b6b4be1d999cb0f64712678d09de972ce681e82882"

cd ./orchestrator && cargo build && cp ./target/debug/gbt /usr/local/bin/gbt

gbt --address-prefix="$ADDRESS_PREFIX" orchestrator \
--fees="$FEES" \
--cosmos-grpc="$GRPC" \
--ethereum-rpc="$ETHRPC" \
--gravity-contract-address="$CONTRACT_ADDR" \
--ethereum-key="${ETH_PRIV_KEY_HEX}" \
--cosmos-phrase="$COSMOS_ORCH_MNEMONIC"
21 changes: 21 additions & 0 deletions module/x/gravity/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (

// InitGenesis starts a chain from a genesis state
func InitGenesis(ctx sdk.Context, k Keeper, data types.GenesisState) {
var lastTxPoolId uint64 = 1
var lastBatchNonce uint64 = 1

k.SetParams(ctx, *data.Params)
// reset valsets in state
for _, vs := range data.Valsets {
Expand All @@ -24,7 +27,19 @@ func InitGenesis(ctx sdk.Context, k Keeper, data types.GenesisState) {
for _, batch := range data.Batches {
// TODO: block height?
k.StoreBatchUnsafe(ctx, batch)
if batch.BatchNonce > lastBatchNonce {
lastBatchNonce = batch.BatchNonce
}
for _, tx := range batch.Transactions {
if err := k.setPoolEntry(ctx, tx); err != nil {
panic(err)
}
if tx.Id > lastTxPoolId {
lastTxPoolId = tx.Id
}
}
}
k.setIncrementID(ctx, types.KeyLastOutgoingBatchID, lastTxPoolId+1)

// reset batch confirmations in state
for _, conf := range data.BatchConfirms {
Expand All @@ -48,8 +63,14 @@ func InitGenesis(ctx sdk.Context, k Keeper, data types.GenesisState) {
if err := k.setPoolEntry(ctx, tx); err != nil {
panic(err)
}
k.appendToUnbatchedTXIndex(ctx, tx.Erc20Fee.Contract, *tx.Erc20Fee, tx.Id)
if tx.Id > lastTxPoolId {
lastTxPoolId = tx.Id
}
}

k.setIncrementID(ctx, types.KeyLastTXPoolID, lastTxPoolId+1)

// reset attestations in state
for _, att := range data.Attestations {
att := att
Expand Down
7 changes: 7 additions & 0 deletions module/x/gravity/keeper/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,10 @@ func (k Keeper) autoIncrementID(ctx sdk.Context, idKey []byte) uint64 {
store.Set(idKey, bz)
return id
}

func (k Keeper) setIncrementID(ctx sdk.Context, idKey []byte, id uint64) uint64 {
store := ctx.KVStore(k.storeKey)
bz := sdk.Uint64ToBigEndian(id)
store.Set(idKey, bz)
return id
}

0 comments on commit c2f4158

Please sign in to comment.