Skip to content

Commit

Permalink
chore(*): rename BlockPeriod to reflect nanoseconds (#1804)
Browse files Browse the repository at this point in the history
The value we set in the e2e app is in nanoseconds, so let's rename the
fields to reflect this.

issue: none

---------

Co-authored-by: Kevin Halliday <kevin@omni.network>
  • Loading branch information
arajasek and kevinhalliday authored Sep 4, 2024
1 parent 7df27d3 commit b97a35a
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 78 deletions.
2 changes: 1 addition & 1 deletion contracts/allocs/devnet.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/allocs/mainnet.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/allocs/omega.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/allocs/staging.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/bindings/allocpredeploys.go

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions contracts/bindings/portalregistry.go

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions contracts/core/src/xchain/PortalRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract PortalRegistry is OwnableUpgradeable {
address indexed addr,
uint64 deployHeight,
uint64 attestInterval,
uint64 blockPeriod,
uint64 blockPeriodNs,
uint64[] shards,
string name
);
Expand All @@ -43,7 +43,7 @@ contract PortalRegistry is OwnableUpgradeable {
* @custom:field chainId The chain ID of the deployment.
* @custom:field deployHeight The height at which the deployment was deployed.
* @custom:field attestInterval The interval, in blocks, at which validators must attest, even if empty.
* @custom:field blockPeriod The block period of the chain deployed to, in milliseconds.
* @custom:field blockPeriodNs The block period of the chain deployed to, in nanoseconds.
* @custom:field shards Supported shards of the deployment.
* @custom:field name The name of the chain deployed to (ex "omni_evm", "ethereum")
*/
Expand All @@ -52,7 +52,7 @@ contract PortalRegistry is OwnableUpgradeable {
uint64 chainId;
uint64 deployHeight;
uint64 attestInterval;
uint64 blockPeriod;
uint64 blockPeriodNs;
uint64[] shards;
string name;
}
Expand Down Expand Up @@ -105,8 +105,8 @@ contract PortalRegistry is OwnableUpgradeable {
require(dep.addr != address(0), "PortalRegistry: zero addr");
require(dep.chainId > 0, "PortalRegistry: zero chain ID");
require(dep.attestInterval > 0, "PortalRegistry: zero interval");
require(dep.blockPeriod <= uint64(type(int64).max), "PortalRegistry: period too large");
require(dep.blockPeriod > 0, "PortalRegistry: zero period");
require(dep.blockPeriodNs <= uint64(type(int64).max), "PortalRegistry: period too large");
require(dep.blockPeriodNs > 0, "PortalRegistry: zero period");
require(bytes(dep.name).length > 0, "PortalRegistry: no name");
require(dep.shards.length > 0, "PortalRegistry: no shards");

Expand All @@ -123,7 +123,7 @@ contract PortalRegistry is OwnableUpgradeable {
chainIds.push(dep.chainId);

emit PortalRegistered(
dep.chainId, dep.addr, dep.deployHeight, dep.attestInterval, dep.blockPeriod, dep.shards, dep.name
dep.chainId, dep.addr, dep.deployHeight, dep.attestInterval, dep.blockPeriodNs, dep.shards, dep.name
);
}
}
10 changes: 5 additions & 5 deletions contracts/core/test/xchain/PortalRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ contract PortalRegistry_Test is Test {
reg.register(dep);

// period cannot be bigger than type(int64).max
dep.blockPeriod = uint64(type(int64).max) + 1;
dep.blockPeriodNs = uint64(type(int64).max) + 1;
vm.expectRevert("PortalRegistry: period too large");
vm.prank(owner);
reg.register(dep);
dep.blockPeriod = 1000; // 1 second in ms
dep.blockPeriodNs = 1000;

// Must have name
vm.expectRevert("PortalRegistry: no name");
Expand All @@ -92,7 +92,7 @@ contract PortalRegistry_Test is Test {
dep.shards[1] = ConfLevel.Latest;
vm.expectEmit();
emit PortalRegistered(
dep.chainId, dep.addr, dep.deployHeight, dep.attestInterval, dep.blockPeriod, dep.shards, dep.name
dep.chainId, dep.addr, dep.deployHeight, dep.attestInterval, dep.blockPeriodNs, dep.shards, dep.name
);
vm.prank(owner);
reg.register(dep);
Expand All @@ -115,7 +115,7 @@ contract PortalRegistry_Test is Test {

vm.expectEmit();
emit PortalRegistered(
dep.chainId, dep.addr, dep.deployHeight, dep.attestInterval, dep.blockPeriod, dep.shards, dep.name
dep.chainId, dep.addr, dep.deployHeight, dep.attestInterval, dep.blockPeriodNs, dep.shards, dep.name
);

vm.prank(owner);
Expand All @@ -137,7 +137,7 @@ contract PortalRegistry_Test is Test {
deployHeight: chainId * 1234,
name: string(abi.encodePacked("omni_evm_", chainId)),
attestInterval: chainId * 60 * 60 * 1000,
blockPeriod: chainId * 1000,
blockPeriodNs: chainId * 1000,
shards: new uint64[](2)
});

Expand Down
10 changes: 8 additions & 2 deletions e2e/app/portalregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/omni-network/omni/lib/log"
"github.com/omni-network/omni/lib/netconf"
"github.com/omni-network/omni/lib/tutil"
"github.com/omni-network/omni/lib/umath"
"github.com/omni-network/omni/lib/xchain"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -148,11 +149,16 @@ func toPortalDepls(def Definition, chains []types.EVMChain) (map[uint64]bindings
return nil, errors.New("missing info", "chain", chain.ChainID)
}

blockPeriodNs, err := umath.ToUint64(chain.BlockPeriod.Nanoseconds())
if err != nil {
return nil, errors.Wrap(err, "block period ns")
}

deps[chain.ChainID] = bindings.PortalRegistryDeployment{
Name: chain.Name,
ChainId: chain.ChainID,
Addr: info.Address,
BlockPeriod: uint64(chain.BlockPeriod),
BlockPeriodNs: blockPeriodNs,
AttestInterval: chain.AttestInterval(def.Testnet.Network),
DeployHeight: info.Height,
Shards: chain.ShardsUint64(),
Expand Down Expand Up @@ -204,7 +210,7 @@ func startAddingMockPortals(ctx context.Context, def Definition) func() error {
Addr: tutil.RandomAddress(),
DeployHeight: chainID, // does not matter
AttestInterval: 60, // 60 blocks,
BlockPeriod: 1000, // 1 second
BlockPeriodNs: uint64(time.Second),
Shards: []uint64{uint64(xchain.ShardFinalized0)},
Name: fmt.Sprintf("mock-portal-%d", chainID),
}
Expand Down
2 changes: 1 addition & 1 deletion halo/genutil/evm/testdata/TestMakeEVMGenesis.golden

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion halo/registry/keeper/logeventproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (k Keeper) Deliver(ctx context.Context, _ common.Hash, elog *evmenginetypes
DeployHeight: reg.DeployHeight,
ShardIds: reg.Shards,
AttestInterval: reg.AttestInterval,
BlockPeriodMs: reg.BlockPeriod,
BlockPeriodNs: reg.BlockPeriodNs,
Name: reg.Name,
})
default:
Expand Down
2 changes: 1 addition & 1 deletion halo/registry/keeper/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (k Keeper) Network(ctx context.Context, req *types.NetworkRequest) (*types.
DeployHeight: portal.GetDeployHeight(),
ShardIds: portal.GetShardIds(),
AttestInterval: portal.GetAttestInterval(),
BlockPeriodMs: portal.GetBlockPeriodMs(),
BlockPeriodNs: portal.GetBlockPeriodNs(),
Name: portal.GetName(),
})
}
Expand Down
10 changes: 5 additions & 5 deletions halo/registry/keeper/registry.pb.go

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

2 changes: 1 addition & 1 deletion halo/registry/keeper/registry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ message Portal {
uint64 deploy_height = 3; // Height this portal contract was deployed at
repeated uint64 shard_ids = 4; // Shard IDs supported by this portal
uint64 attest_interval = 5; // The interval, in blocks, at which validators must attest, even if empty
uint64 block_period_ms = 6; // The block period of the chain deployed to, in milliseconds.
uint64 block_period_ns = 6; // The block period of the chain deployed to, in nanoseconds.
string name = 7; // The name of the chain deployed to (ex "omni_evm", "ethereum")
}
66 changes: 33 additions & 33 deletions halo/registry/types/query.pb.go

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

2 changes: 1 addition & 1 deletion halo/registry/types/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ message Portal {
uint64 deploy_height = 3; // Height this portal contract was deployed at
repeated uint64 shard_ids = 4; // Shard IDs supported by this portal
uint64 attest_interval = 5; // The interval, in blocks, at which validators must attest, even if empty
uint64 block_period_ms = 6; // The block period of the chain deployed to, in milliseconds.
uint64 block_period_ns = 6; // The block period of the chain deployed to, in nanoseconds.
string name = 7; // The name of the chain deployed to (ex "omni_evm", "ethereum")
}
4 changes: 2 additions & 2 deletions lib/netconf/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func networkFromPortals(ctx context.Context, network ID, portals []bindings.Port
var chains []Chain
for _, portal := range portals {
// PortalRegistry guarantees BlockPeriod <= MaxInt64, but we check here to be safe.
periodNanos, err := umath.ToInt64(portal.BlockPeriod)
periodNanos, err := umath.ToInt64(portal.BlockPeriodNs)
if err != nil {
return Network{}, err
}
Expand Down Expand Up @@ -227,7 +227,7 @@ func toPortalBindings(portals []*rtypes.Portal) []bindings.PortalRegistryDeploym
DeployHeight: p.DeployHeight,
Shards: p.ShardIds,
AttestInterval: p.AttestInterval,
BlockPeriod: p.BlockPeriodMs,
BlockPeriodNs: p.BlockPeriodNs,
Name: p.Name,
}
}
Expand Down

0 comments on commit b97a35a

Please sign in to comment.