Skip to content

Commit

Permalink
set observe count for even is observer set is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Dec 9, 2024
1 parent 8ecf2dd commit 863b4cd
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ test-sim-fullappsimulation:
$(call run-sim-test,"TestFullAppSimulation",TestFullAppSimulation,100,200,30m)

test-sim-import-export:
$(call run-sim-test,"test-import-export",TestAppImportExport,50,200,30m)
$(call run-sim-test,"test-import-export",TestAppImportExport,100,200,30m)

test-sim-after-import:
$(call run-sim-test,"test-sim-after-import",TestAppSimulationAfterImport,100,200,30m)
Expand Down
67 changes: 67 additions & 0 deletions simulation/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,14 @@ func TestAppImportExport(t *testing.T) {
storeA := ctxSimApp.KVStore(skp.A)
storeB := ctxNewSimApp.KVStore(skp.B)

a, b := CountKVStores(storeA, storeB, skp.SkipPrefixes)
if a != b {
t.Logf("storeA: %d, storeB: %d", a, b)
t.Log("key prefix: ", skp.A.Name())
//FindDiffKeys(storeA, storeB)
//t.Fail()
}

failedKVAs, failedKVBs := sdk.DiffKVStores(storeA, storeB, skp.SkipPrefixes)
require.Equal(t, len(failedKVAs), len(failedKVBs), "unequal sets of key-values to compare")

Expand Down Expand Up @@ -573,3 +581,62 @@ func TestAppSimulationAfterImport(t *testing.T) {
)
require.NoError(t, err)
}

// DiffKVStores compares two KVstores and returns all the key/value pairs
// that differ from one another. It also skips value comparison for a set of provided prefixes.
func CountKVStores(a sdk.KVStore, b sdk.KVStore, _ [][]byte) (int, int) {
iterA := a.Iterator(nil, nil)

defer iterA.Close()

iterB := b.Iterator(nil, nil)

defer iterB.Close()

countA := 0
countB := 0

for iterA.Valid() {
countA++
iterA.Next()
}

for iterB.Valid() {
countB++
iterB.Next()
}
return countA, countB
}

func FindDiffKeys(a sdk.KVStore, b sdk.KVStore) {

keysA := map[string]bool{}
keysB := map[string]bool{}
iterA := a.Iterator(nil, nil)

defer iterA.Close()

iterB := b.Iterator(nil, nil)

defer iterB.Close()

for iterA.Valid() {
k := string(iterA.Key())
iterA.Next()
keysA[k] = true

}

for iterB.Valid() {
kb := string(iterB.Key())
iterB.Next()
keysB[kb] = true
}

for k := range keysA {
if _, ok := keysB[k]; !ok {
fmt.Println("Key in A not in B", k)
}
}

}
26 changes: 13 additions & 13 deletions x/crosschain/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
cctx := *elem
k.SetCrossChainTx(ctx, cctx)
// set mapping inboundHash -> cctxIndex
in, _ := k.GetInboundHashToCctx(ctx, cctx.InboundParams.ObservedHash)
in.InboundHash = cctx.InboundParams.ObservedHash
found := false
for _, cctxIndex := range in.CctxIndex {
if cctxIndex == cctx.Index {
found = true
break
}
}
if !found {
in.CctxIndex = append(in.CctxIndex, cctx.Index)
}
k.SetInboundHashToCctx(ctx, in)
//in, _ := k.GetInboundHashToCctx(ctx, cctx.InboundParams.ObservedHash)
//in.InboundHash = cctx.InboundParams.ObservedHash
//found := false
//for _, cctxIndex := range in.CctxIndex {
// if cctxIndex == cctx.Index {
// found = true
// break
// }
//}
//if !found {
// in.CctxIndex = append(in.CctxIndex, cctx.Index)
//}
//k.SetInboundHashToCctx(ctx, in)

if cctx.CctxStatus.Status == types.CctxStatus_Aborted && cctx.InboundParams.CoinType == coin.CoinType_Zeta && cctx.CctxStatus.IsAbortRefunded == false {
k.AddZetaAbortedAmount(ctx, keeper.GetAbortedAmount(cctx))
Expand Down
23 changes: 15 additions & 8 deletions x/observer/genesis.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package observer

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/zeta-chain/node/pkg/chains"
Expand All @@ -11,10 +13,21 @@ import (
// InitGenesis initializes the observer module's state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
observerCount := uint64(0)

fmt.Println("Observer Set Len : ", genState.Observers.Len())

observerCount := uint64(genState.Observers.Len())

if genState.Observers.Len() > 0 {
k.SetObserverSet(ctx, genState.Observers)
observerCount = uint64(len(genState.Observers.ObserverList))
} else {
k.SetObserverSet(ctx, types.ObserverSet{})
}

if genState.LastObserverCount != nil {
k.SetLastObserverCount(ctx, genState.LastObserverCount)
} else {
k.SetLastObserverCount(ctx, &types.LastObserverCount{LastChangeHeight: 0, Count: observerCount})
}

// if chain params are defined set them
Expand Down Expand Up @@ -82,12 +95,6 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
})
}

if genState.LastObserverCount != nil {
k.SetLastObserverCount(ctx, genState.LastObserverCount)
} else {
k.SetLastObserverCount(ctx, &types.LastObserverCount{LastChangeHeight: 0, Count: observerCount})
}

tss := types.TSS{}
if genState.Tss != nil {
tss = *genState.Tss
Expand Down

0 comments on commit 863b4cd

Please sign in to comment.