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

Block Delay Parameter #171

Merged
merged 18 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
switch param name and default
  • Loading branch information
AdityaSripal committed May 18, 2021
commit 43f10893bc58588ae0146976b6eb87f89487f332
2 changes: 1 addition & 1 deletion docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2408,7 +2408,7 @@ Params defines the set of Connection parameters.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `max_time_per_block` | [uint64](#uint64) | | maximum time expected per block, used to enforce block delay. |
| `expected_time_per_block` | [uint64](#uint64) | | expected time per block, used to enforce block delay. |



Expand Down
8 changes: 4 additions & 4 deletions modules/core/03-connection/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import (
"github.com/cosmos/ibc-go/modules/core/03-connection/types"
)

// GetMaxTimePerBlock retrieves the maximum time per block from the paramstore
func (k Keeper) GetMaxTimePerBlock(ctx sdk.Context) uint64 {
// GetExpectedTimePerBlock retrieves the expected time per block from the paramstore
func (k Keeper) GetExpectedTimePerBlock(ctx sdk.Context) uint64 {
var res uint64
k.paramSpace.Get(ctx, types.KeyMaxTimePerBlock, &res)
k.paramSpace.Get(ctx, types.KeyExpectedTimePerBlock, &res)
return res
}

// GetParams returns the total set of ibc-connection parameters.
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
return types.NewParams(k.GetMaxTimePerBlock(ctx))
return types.NewParams(k.GetExpectedTimePerBlock(ctx))
}

// SetParams sets the total set of ibc-connection parameters.
Expand Down
4 changes: 2 additions & 2 deletions modules/core/03-connection/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ func (suite *KeeperTestSuite) TestParams() {
params := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetParams(suite.chainA.GetContext())
suite.Require().Equal(expParams, params)

expParams.MaxTimePerBlock = 10
expParams.ExpectedTimePerBlock = 10
suite.chainA.App.GetIBCKeeper().ConnectionKeeper.SetParams(suite.chainA.GetContext(), expParams)
params = suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetParams(suite.chainA.GetContext())
suite.Require().Equal(uint64(10), expParams.MaxTimePerBlock)
suite.Require().Equal(uint64(10), expParams.ExpectedTimePerBlock)
}
14 changes: 7 additions & 7 deletions modules/core/03-connection/keeper/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,16 @@ func (k Keeper) VerifyNextSequenceRecv(
}

// getBlockDelay calculates the block delay period from the time delay of the connection
// and the maximum expected time per block.
// and the expected time per block.
func (k Keeper) getBlockDelay(ctx sdk.Context, connection exported.ConnectionI) uint64 {
// maxTimePerBlock should never be zero, however if it is then return a 0 blcok delay for safety
// as the maxTimePerBlock parameter was not set.
maxTimePerBlock := k.GetMaxTimePerBlock(ctx)
if maxTimePerBlock == 0 {
// expectedTimePerBlock should never be zero, however if it is then return a 0 blcok delay for safety
// as the expectedTimePerBlock parameter was not set.
expectedTimePerBlock := k.GetExpectedTimePerBlock(ctx)
if expectedTimePerBlock == 0 {
return 0
}
// calculate minimum block delay by dividing time delay period
// by the maximum expected time per block. Round up the block delay.
// by the expected time per block. Round up the block delay.
timeDelay := connection.GetDelayPeriod()
return uint64(math.Ceil(float64(timeDelay) / float64(maxTimePerBlock)))
return uint64(math.Ceil(float64(timeDelay) / float64(expectedTimePerBlock)))
}
114 changes: 57 additions & 57 deletions modules/core/03-connection/types/connection.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 9 additions & 10 deletions modules/core/03-connection/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import (
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

// DefaultTimePerBlock is the default value for maximum time
// expected per block.
const DefaultTimePerBlock = time.Hour
// DefaultTimePerBlock is the default value for expected time per block.
const DefaultTimePerBlock = 30 * time.Second

// KeyMaxTimePerBlock is store's key for MaxTimePerBlock parameter
var KeyMaxTimePerBlock = []byte("MaxTimePerBlock")
// KeyExpectedTimePerBlock is store's key for ExpectedTimePerBlock parameter
var KeyExpectedTimePerBlock = []byte("ExpectedTimePerBlock")

// ParamKeyTable type declaration for parameters
func ParamKeyTable() paramtypes.KeyTable {
Expand All @@ -22,7 +21,7 @@ func ParamKeyTable() paramtypes.KeyTable {
// NewParams creates a new parameter configuration for the ibc connection module
func NewParams(timePerBlock uint64) Params {
return Params{
MaxTimePerBlock: timePerBlock,
ExpectedTimePerBlock: timePerBlock,
}
}

Expand All @@ -31,18 +30,18 @@ func DefaultParams() Params {
return NewParams(uint64(DefaultTimePerBlock))
}

// Validate ensures MaxTimePerBlock is non-zero
// Validate ensures ExpectedTimePerBlock is non-zero
func (p Params) Validate() error {
if p.MaxTimePerBlock == 0 {
return fmt.Errorf("MaxTimePerBlock cannot be zero")
if p.ExpectedTimePerBlock == 0 {
return fmt.Errorf("ExpectedTimePerBlock cannot be zero")
}
return nil
}

// ParamSetPairs implements params.ParamSet
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(KeyMaxTimePerBlock, p.MaxTimePerBlock, validateParams),
paramtypes.NewParamSetPair(KeyExpectedTimePerBlock, p.ExpectedTimePerBlock, validateParams),
}
}

Expand Down
4 changes: 2 additions & 2 deletions proto/ibc/core/connection/v1/connection.proto
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ message Version {

// Params defines the set of Connection parameters.
message Params {
// maximum time expected per block, used to enforce block delay.
uint64 max_time_per_block = 1 [(gogoproto.moretags) = "yaml:\"max_time_per_block\""];
// expected time per block, used to enforce block delay.
uint64 expected_time_per_block = 1 [(gogoproto.moretags) = "yaml:\"expected_time_per_block\""];
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
}