Skip to content

Commit

Permalink
Perma stash model tweaks (prototype)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel committed Dec 6, 2022
1 parent c238f4b commit 3a22a6b
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 11 deletions.
14 changes: 12 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,20 @@ require (
nhooyr.io/websocket v1.8.6 // indirect
)

// replace (
// github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76
// github.com/cosmos/ibc-go/v3 => github.com/informalsystems/ibc-go/v3 v3.0.0-beta1.0.20221121181828-c75c185d20b2
// github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
// github.com/stretchr/testify => github.com/stretchr/testify v1.7.1
// google.golang.org/grpc => google.golang.org/grpc v1.33.2
// )

replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76
github.com/cosmos/ibc-go/v3 => github.com/informalsystems/ibc-go/v3 v3.0.0-beta1.0.20221121181828-c75c185d20b2
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/stretchr/testify => github.com/stretchr/testify v1.7.1
google.golang.org/grpc => google.golang.org/grpc v1.33.2
github.com/stretchr/testify => github.com/stretchr/testify v1.7.1
github.com/cosmos/ibc-go/v3 => /Users/danwt/Documents/work/informal-ibc-go // c75c185d20b2
github.com/cosmos/cosmos-sdk => /Users/danwt/Documents/work/cosmos-sdk // 9c145c827001
github.com/tendermint/tendermint => /Users/danwt/Documents/work/tendermint // v0.34.23
)
2 changes: 2 additions & 0 deletions tests/difference/core/driver/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type InitState struct {
ConsensusParams *abci.ConsensusParams
ValStates ValStates
MaxEntries int
SlashMeterInitValue int64
}

var initState InitState
Expand All @@ -63,6 +64,7 @@ func init() {
Trusting: time.Second * 49,
MaxClockDrift: time.Second * 10000,
BlockSeconds: time.Second * 6,
SlashMeterInitValue: 100,
ValStates: ValStates{
Delegation: []int{4000, 3000, 2000, 1000},
Tokens: []int{5000, 4000, 3000, 2000},
Expand Down
12 changes: 9 additions & 3 deletions tests/difference/core/driver/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ func (s *CoreSuite) TestAssumptions() {
s.T().Fatal(FAIL_MSG)
}

// Slash meter value is correct
slashMeterE := initState.SlashMeterInitValue
slashMeter := s.providerChain().App.(*appProvider.App).ProviderKeeper.GetSlashMeter(s.ctx(P))
if !sdk.NewInt(slashMeterE).Equal(slashMeter) {
s.T().Fatal(FAIL_MSG)
}

// Delegator balance is correct
s.Require().Equal(int64(initState.InitialDelegatorTokens), s.delegatorBalance())

Expand Down Expand Up @@ -426,7 +433,7 @@ func (s *CoreSuite) TestAssumptions() {
// Test a set of traces
func (s *CoreSuite) TestTraces() {
s.traces = Traces{
Data: LoadTraces("traces.json"),
Data: LoadTraces("tracesAlt.json"),
}
// s.traces.Data = []TraceData{s.traces.Data[69]}
for i := range s.traces.Data {
Expand All @@ -453,8 +460,7 @@ func (s *CoreSuite) TestTraces() {
}

func TestCoreSuite(t *testing.T) {
// TODO: Reenable diff tests once model is updated
// suite.Run(t, new(CoreSuite))
suite.Run(t, new(CoreSuite))
}

// SetupTest sets up the test suite in a 'zero' state which matches
Expand Down
6 changes: 6 additions & 0 deletions tests/difference/core/driver/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,12 @@ func (b *Builder) build() {

b.setSlashParams()

prams := b.providerKeeper().GetParams(b.ctx(P))
prams.SlashMeterReplenishFraction = "1.0"
prams.SlashMeterReplenishPeriod = time.Second * 1
b.providerKeeper().SetParams(b.ctx(P), prams)
b.providerKeeper().SetSlashMeter(b.ctx(P), sdk.NewInt(b.initState.SlashMeterInitValue))

// Set light client params to match model
tmConfig := ibctesting.NewTendermintConfig()
tmConfig.UnbondingPeriod = b.initState.UnbondingP
Expand Down
1 change: 1 addition & 0 deletions tests/difference/core/model/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ type ModelInitState = {
downtimeSlashAcks: number[];
tombstoned: boolean[];
matureUnbondingOps: number[];
queue: (Slash | VscMatured)[];
};
};

Expand Down
1 change: 1 addition & 0 deletions tests/difference/core/model/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const MODEL_INIT_STATE: ModelInitState = {
downtimeSlashAcks: [],
tombstoned: [false, false, false, false],
matureUnbondingOps: [],
queue: [],
},
staking: {
delegation: [4000, 3000, 2000, 1000],
Expand Down
23 changes: 17 additions & 6 deletions tests/difference/core/model/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ class CCVProvider {
tombstoned: boolean[];
// unbonding operations to be completed in EndBlock
matureUnbondingOps: number[];
// queue
queue: (Slash | VscMatured)[];

constructor(model: Model, { ccvP }: ModelInitState) {
this.m = model;
Expand All @@ -382,6 +384,8 @@ class CCVProvider {

endBlockCIS = () => {
this.vscIDtoH[this.vscID] = this.m.h[P] + 1;

this.processPackets();
};

endBlockVSU = () => {
Expand Down Expand Up @@ -420,12 +424,19 @@ class CCVProvider {
};

onReceive = (data: PacketData) => {
// It's sufficient to use isDowntime field as differentiator
if ('isDowntime' in data) {
this.onReceiveSlash(data);
} else {
this.onReceiveVSCMatured(data);
}
this.queue.push(data);
};

processPackets = () => {
this.queue.forEach((data) => {
// It's sufficient to use isDowntime field as differentiator
if ('isDowntime' in data) {
this.onReceiveSlash(data);
} else {
this.onReceiveVSCMatured(data);
}
});
this.queue = [];
};

onReceiveVSCMatured = (data: VscMatured) => {
Expand Down

0 comments on commit 3a22a6b

Please sign in to comment.