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

#533 throttle normal operation diff testing PR rebase 2 #580

Merged
merged 3 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 18 additions & 6 deletions tests/difference/core/driver/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ func (s *CoreSuite) matchState() {
// TODO: delegations
s.Require().Equalf(int64(s.traces.DelegatorTokens()), s.delegatorBalance(), diagnostic+"P del balance mismatch")
for j := 0; j < initState.NumValidators; j++ {
s.Require().Equalf(s.traces.Jailed(j) != nil, s.isJailed(int64(j)), diagnostic+"P jail status mismatch for val %d", j)
a := s.traces.Jailed(j) != nil
b := s.isJailed(int64(j))
s.Require().Equalf(a, b, diagnostic+"P jail status mismatch for val %d", j)
}
}
if chain == C {
Expand All @@ -259,6 +261,7 @@ func (s *CoreSuite) matchState() {
}

func (s *CoreSuite) executeTrace() {

for i := range s.traces.Actions() {
s.traces.CurrentActionIx = i

Expand Down Expand Up @@ -310,6 +313,8 @@ func (s *CoreSuite) TestAssumptions() {
s.T().Fatal(FAIL_MSG)
}

// TODO: write assumption that checks that throttle params are appropriate

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

Expand Down Expand Up @@ -428,9 +433,10 @@ func (s *CoreSuite) TestTraces() {
s.traces = Traces{
Data: LoadTraces("traces.json"),
}
// s.traces.Data = []TraceData{s.traces.Data[69]}
shortest := -1
shortestLen := 10000000000
for i := range s.traces.Data {
s.Run(fmt.Sprintf("Trace num: %d", i), func() {
if !s.Run(fmt.Sprintf("Trace num: %d", i), func() {
// Setup a new pair of chains for each trace
s.SetupTest()

Expand All @@ -448,13 +454,19 @@ func (s *CoreSuite) TestTraces() {
// Record information about the trace, for debugging
// diagnostics.
s.executeTrace()
})
}) {
if s.traces.CurrentActionIx < shortestLen {
shortest = s.traces.CurrentTraceIx
shortestLen = s.traces.CurrentActionIx
}
}
}
fmt.Println("Shortest [traceIx, actionIx]:", shortest, shortestLen)

}

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
7 changes: 7 additions & 0 deletions tests/difference/core/driver/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,13 @@ func (b *Builder) build() {

b.setSlashParams()

// TODO: tidy up before merging into main
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().InitializeSlashMeter(b.ctx(P))

// Set light client params to match model
tmConfig := ibctesting.NewTendermintConfig()
tmConfig.UnbondingPeriod = b.initState.UnbondingP
Expand Down
2 changes: 1 addition & 1 deletion tests/difference/core/driver/traces.json

Large diffs are not rendered by default.

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
29 changes: 25 additions & 4 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,7 @@ class CCVProvider {

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

endBlockVSU = () => {
Expand Down Expand Up @@ -420,14 +423,32 @@ class CCVProvider {
};

onReceive = (data: PacketData) => {
// It's sufficient to use isDowntime field as differentiator
if ('isDowntime' in data) {
this.onReceiveSlash(data);
/*
TODO: tidy up before merging to main
This is some quick prototyping to get the tests passing
We have 1 consumer chain so the slash queue is the global queue
if the queue is empty we can just process the packet.
*/
if (this.queue.length == 0 && !('isDowntime' in data)) {
// Skip the queue
this.onReceiveVSCMatured(data as VscMatured);
} 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) => {
if (this.vscIDtoOpIDs.has(data.vscID)) {
this.vscIDtoOpIDs.get(data.vscID)!.forEach((opID: number) => {
Expand Down