Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shaspitz committed Sep 20, 2023
1 parent 2318279 commit 01b001f
Show file tree
Hide file tree
Showing 9 changed files with 362 additions and 365 deletions.
20 changes: 10 additions & 10 deletions tests/e2e/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2047,16 +2047,16 @@ func (tr TestRun) assignConsumerPubKey(action assignConsumerPubKeyAction, verbos

// slashMeterReplenishmentAction polls the slash meter on provider until value is achieved
type slashMeterReplenishmentAction struct {
targetValue int64
TargetValue int64
// panic if timeout is exceeded
timeout time.Duration
Timeout time.Duration
}

func (tr TestRun) waitForSlashMeterReplenishment(
action slashMeterReplenishmentAction,
verbose bool,
) {
timeout := time.Now().Add(action.timeout)
timeout := time.Now().Add(action.Timeout)
initialSlashMeter := tr.getSlashMeter()

if initialSlashMeter >= 0 {
Expand All @@ -2070,28 +2070,28 @@ func (tr TestRun) waitForSlashMeterReplenishment(
}

// check if meter has reached target value
if slashMeter >= action.targetValue {
if slashMeter >= action.TargetValue {
break
}

if time.Now().After(timeout) {
panic(fmt.Sprintf("\n\nwaitForSlashMeterReplenishment has timed out after: %s\n\n", action.timeout))
panic(fmt.Sprintf("\n\nwaitForSlashMeterReplenishment has timed out after: %s\n\n", action.Timeout))
}

tr.WaitTime(5 * time.Second)
}
}

type WaitTimeAction struct {
consumer chainID
waitTime time.Duration
type waitTimeAction struct {
Consumer ChainID
WaitTime time.Duration
}

func (tr TestRun) waitForTime(
action WaitTimeAction,
action waitTimeAction,
verbose bool,
) {
tr.WaitTime(action.waitTime)
tr.WaitTime(action.WaitTime)
}

// GetPathNameForGorelayer returns the name of the path between two given chains used by Gorelayer.
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (tr *TestRun) runStep(step Step, verbose bool) {
tr.assignConsumerPubKey(action, verbose)
case slashMeterReplenishmentAction:
tr.waitForSlashMeterReplenishment(action, verbose)
case WaitTimeAction:
case waitTimeAction:
tr.waitForTime(action, verbose)
case startRelayerAction:
tr.startRelayer(action, verbose)
Expand Down
14 changes: 7 additions & 7 deletions tests/e2e/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ type ChainState struct {
RepresentativePowers *map[ValidatorID]uint
Params *[]Param
Rewards *Rewards
ConsumerChains *map[chainID]bool
AssignedKeys *map[validatorID]string
ProviderKeys *map[validatorID]string // validatorID: validator provider key
ConsumerChains *map[ChainID]bool
AssignedKeys *map[ValidatorID]string
ProviderKeys *map[ValidatorID]string // validatorID: validator provider key
ConsumerPendingPacketQueueSize *uint // Only relevant to consumer chains
RegisteredConsumerRewardDenoms *[]string
}
Expand Down Expand Up @@ -661,7 +661,7 @@ func (tr TestRun) getProviderAddressFromConsumer(consumerChain ChainID, validato
func (tr TestRun) getSlashMeter() int64 {
//#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments.
cmd := exec.Command("docker", "exec",
tr.containerConfig.instanceName, tr.chainConfigs[chainID("provi")].binaryName,
tr.containerConfig.InstanceName, tr.chainConfigs[ChainID("provi")].BinaryName,

"query", "provider", "throttle-state",
`--node`, tr.getQueryNode(ChainID("provi")),
Expand Down Expand Up @@ -698,9 +698,9 @@ func (tr TestRun) getRegisteredConsumerRewardDenoms(chain ChainID) []string {
return rewardDenoms
}

func (tr TestRun) getPendingPacketQueueSize(chain chainID) uint {
func (tr TestRun) getPendingPacketQueueSize(chain ChainID) uint {
//#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments.
cmd := exec.Command("docker", "exec", tr.containerConfig.instanceName, tr.chainConfigs[chain].binaryName,
cmd := exec.Command("docker", "exec", tr.containerConfig.InstanceName, tr.chainConfigs[chain].BinaryName,

"query", "ccvconsumer", "throttle-state",
`--node`, tr.getQueryNode(chain),
Expand All @@ -719,7 +719,7 @@ func (tr TestRun) getPendingPacketQueueSize(chain chainID) uint {
return uint(len(packetData))
}

func (tr TestRun) getValidatorNode(chain chainID, validator validatorID) string {
func (tr TestRun) getValidatorNode(chain ChainID, validator ValidatorID) string {
// for CometMock, validatorNodes are all the same address as the query node (which is CometMocks address)
if tr.useCometmock {
return tr.getQueryNode(chain)
Expand Down
120 changes: 60 additions & 60 deletions tests/e2e/steps_downtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ func stepsDowntime(consumerName string) []Step {
ValidatorID("carol"): 501,
},
},
chainID(consumerName): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 509,
ChainID(consumerName): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 509,
// Bob's stake may or may not be slashed at this point depending on comet vs cometmock
// See https://github.com/cosmos/interchain-security/issues/1304
validatorID("carol"): 501,
ValidatorID("carol"): 501,
},
},
},
Expand Down Expand Up @@ -278,13 +278,13 @@ func stepsThrottledDowntime(consumerName string) []Step {
Chain: ChainID(consumerName),
Validator: ValidatorID("bob"),
},
state: State{
State: State{
// slash packet queued for bob on consumer, but powers not affected on either chain yet
chainID("provi"): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 511,
validatorID("bob"): 500,
validatorID("carol"): 500,
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 511,
ValidatorID("bob"): 500,
ValidatorID("carol"): 500,
},
},
ChainID(consumerName): ChainState{
Expand Down Expand Up @@ -332,19 +332,19 @@ func stepsThrottledDowntime(consumerName string) []Step {
Chain: ChainID(consumerName),
Validator: ValidatorID("carol"),
},
state: State{
chainID("provi"): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 511,
validatorID("bob"): 0,
validatorID("carol"): 500,
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 511,
ValidatorID("bob"): 0,
ValidatorID("carol"): 500,
},
},
chainID(consumerName): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 511,
validatorID("bob"): 500, // VSC packet jailing bob is not yet relayed to consumer
validatorID("carol"): 500,
ChainID(consumerName): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 511,
ValidatorID("bob"): 500, // VSC packet jailing bob is not yet relayed to consumer
ValidatorID("carol"): 500,
},
ConsumerPendingPacketQueueSize: uintPtr(1), // carol's downtime slash packet is queued
},
Expand All @@ -358,39 +358,39 @@ func stepsThrottledDowntime(consumerName string) []Step {
Port: "provider",
Channel: 0,
},
state: State{
chainID("provi"): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 511,
validatorID("bob"): 0,
validatorID("carol"): 500, // slash packet for carol recv by provider, carol not slashed due to throttling
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 511,
ValidatorID("bob"): 0,
ValidatorID("carol"): 500, // slash packet for carol recv by provider, carol not slashed due to throttling
},
},
chainID(consumerName): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 511,
validatorID("bob"): 0, // VSC packet applying bob jailing is also relayed and recv by consumer
validatorID("carol"): 500,
ChainID(consumerName): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 511,
ValidatorID("bob"): 0, // VSC packet applying bob jailing is also relayed and recv by consumer
ValidatorID("carol"): 500,
},
ConsumerPendingPacketQueueSize: uintPtr(1), // slash packet bounced ack keeps carol's downtime slash packet queued
},
},
},
{
action: slashMeterReplenishmentAction{
targetValue: 0, // We just want slash meter to be non-negative
Action: slashMeterReplenishmentAction{
TargetValue: 0, // We just want slash meter to be non-negative

// Slash meter replenish fraction is set to 10%, replenish period is 20 seconds, see config.go
// Meter is initially at 10%, decremented to -23% from bob being jailed. It'll then take three replenishments
// for meter to become positive again. 3*20 = 60 seconds + buffer = 100 seconds
timeout: 100 * time.Second,
},
state: State{
chainID("provi"): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 511,
validatorID("bob"): 0,
validatorID("carol"): 500, // Carol still not slashed, packet must be retried
Timeout: 100 * time.Second,
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 511,
ValidatorID("bob"): 0,
ValidatorID("carol"): 500, // Carol still not slashed, packet must be retried
},
},
ChainID(consumerName): ChainState{
Expand All @@ -408,19 +408,19 @@ func stepsThrottledDowntime(consumerName string) []Step {
// Retry delay period is set to 30 seconds, see config.go,
// wait this amount of time to elapse the period.
{
action: WaitTimeAction{
consumer: chainID(consumerName),
waitTime: 30 * time.Second,
},
state: State{
chainID("provi"): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 511,
validatorID("bob"): 0,
validatorID("carol"): 500,
Action: waitTimeAction{
Consumer: ChainID(consumerName),
WaitTime: 30 * time.Second,
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 511,
ValidatorID("bob"): 0,
ValidatorID("carol"): 500,
},
},
chainID(consumerName): ChainState{
ChainID(consumerName): ChainState{
ConsumerPendingPacketQueueSize: uintPtr(1), // packet still queued
},
},
Expand All @@ -433,15 +433,15 @@ func stepsThrottledDowntime(consumerName string) []Step {
Port: "provider",
Channel: 0,
},
state: State{
chainID("provi"): ChainState{
ValPowers: &map[validatorID]uint{
validatorID("alice"): 511,
validatorID("bob"): 0,
validatorID("carol"): 0, // jailed!
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 511,
ValidatorID("bob"): 0,
ValidatorID("carol"): 0, // jailed!
},
},
chainID(consumerName): ChainState{
ChainID(consumerName): ChainState{
ConsumerPendingPacketQueueSize: uintPtr(0), // relayed slash packet handled ack clears consumer queue
},
},
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func (s *CCVTestSuite) TestRelayAndApplyDowntimePacket() {
timeoutHeight = clienttypes.Height{}
timeoutTimestamp = uint64(s.getFirstBundle().GetCtx().BlockTime().Add(ccv.DefaultCCVTimeoutPeriod).UnixNano())
)
slashPacket := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmVal, stakingtypes.Infraction_INFRACTION_DOWNTIME)
sequence, err := s.getFirstBundle().Path.EndpointA.SendPacket(timeoutHeight, timeoutTimestamp, slashPacket.GetBytes())
slashPacket := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmVal, stakingtypes.Infraction_INFRACTION_DOWNTIME, 1)
sequence, err := s.getFirstBundle().Path.EndpointA.SendPacket(timeoutHeight, timeoutTimestamp, slashPacket.GetData())
s.Require().NoError(err)

// Set outstanding slashing flag for first consumer, it's important to use the consumer's cons addr here
Expand Down
Loading

0 comments on commit 01b001f

Please sign in to comment.