Skip to content

parallelization test contracts & fixes #470

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

Merged
merged 7 commits into from
Jan 8, 2023
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ nitro-replayer/target
nitro-replayer/Cargo.lock
# nitro mac artifact
x/nitro/replay/libnitro_replayer.dylib

# parallelization test build artifact
parallelization/**/artifacts/
parallelization/**/target/
parallelization/**/Cargo.lock
30 changes: 30 additions & 0 deletions aclmapping/bank/mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,42 @@ func MsgSendDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sd
IdentifierTemplate: hex.EncodeToString(authtypes.CreateAddressStoreKeyFromBech32(msgSend.FromAddress)),
},

{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_AUTH_GLOBAL_ACCOUNT_NUMBER,
IdentifierTemplate: hex.EncodeToString(authtypes.GlobalAccountNumberKey),
},

{
ResourceType: sdkacltypes.ResourceType_ANY,
AccessType: sdkacltypes.AccessType_COMMIT,
IdentifierTemplate: utils.DefaultIDTemplate,
},
}

// check if the account exists and add additional write dependency if it doesn't
toAddr, err := sdk.AccAddressFromBech32(msgSend.ToAddress)
if err != nil {
// let msg server handle it
accessOperations = append(accessOperations, sdkacltypes.AccessOperation{
ResourceType: sdkacltypes.ResourceType_ANY,
AccessType: sdkacltypes.AccessType_COMMIT,
IdentifierTemplate: utils.DefaultIDTemplate,
})
return accessOperations, nil
}
if !keeper.AccountKeeper.HasAccount(ctx, toAddr) {
accessOperations = append(accessOperations, sdkacltypes.AccessOperation{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_AUTH_GLOBAL_ACCOUNT_NUMBER,
IdentifierTemplate: hex.EncodeToString(authtypes.GlobalAccountNumberKey),
})
}
accessOperations = append(accessOperations, sdkacltypes.AccessOperation{
ResourceType: sdkacltypes.ResourceType_ANY,
AccessType: sdkacltypes.AccessType_COMMIT,
IdentifierTemplate: utils.DefaultIDTemplate,
})

return accessOperations, nil
}
64 changes: 40 additions & 24 deletions aclmapping/dex/mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,6 @@ func GetDexDependencyGenerators() aclkeeper.DependencyGeneratorMap {
return dependencyGeneratorMap
}

func GetDexMemReadWrite(contract string) []sdkacltypes.AccessOperation {
if contract == "" {
return []sdkacltypes.AccessOperation{}
}

return []sdkacltypes.AccessOperation{
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_DexMem,
IdentifierTemplate: hex.EncodeToString([]byte(contract)),
},
{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_DexMem,
IdentifierTemplate: hex.EncodeToString([]byte(contract)),
},
}
}

func GetLongShortOrderBookOps(contractAddr string, priceDenom string, assetDenom string) []sdkacltypes.AccessOperation {
return []sdkacltypes.AccessOperation{
{
Expand All @@ -68,9 +49,7 @@ func DexPlaceOrdersDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context,

contractAddr := placeOrdersMsg.ContractAddr

aclOps := GetDexMemReadWrite(contractAddr)

aclOps = append(aclOps, []sdkacltypes.AccessOperation{
aclOps := []sdkacltypes.AccessOperation{
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_DEX_NEXT_ORDER_ID,
Expand All @@ -86,7 +65,33 @@ func DexPlaceOrdersDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context,
ResourceType: sdkacltypes.ResourceType_KV_DEX_REGISTERED_PAIR,
IdentifierTemplate: hex.EncodeToString(dextypes.RegisteredPairPrefix(contractAddr)),
},
}...)
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_DEX_MEM_DEPOSIT,
IdentifierTemplate: hex.EncodeToString(append(
dextypes.MemDepositPrefix(contractAddr),
[]byte(placeOrdersMsg.Creator)...,
)),
},
{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_DEX_MEM_DEPOSIT,
IdentifierTemplate: hex.EncodeToString(append(
dextypes.MemDepositPrefix(contractAddr),
[]byte(placeOrdersMsg.Creator)...,
)),
},
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_DEX_MEM_ORDER,
IdentifierTemplate: hex.EncodeToString(dextypes.MemOrderPrefix(contractAddr)),
},
{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_DEX_MEM_ORDER,
IdentifierTemplate: hex.EncodeToString(dextypes.MemOrderPrefix(contractAddr)),
},
}

// Last Operation should always be a commit
aclOps = append(aclOps, *acltypes.CommitAccessOp())
Expand All @@ -100,7 +105,18 @@ func DexCancelOrdersDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context
}
contractAddr := cancelOrdersMsg.ContractAddr

aclOps := GetDexMemReadWrite(contractAddr)
aclOps := []sdkacltypes.AccessOperation{
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_DEX_MEM_CANCEL,
IdentifierTemplate: hex.EncodeToString(dextypes.MemCancelPrefix(contractAddr)),
},
{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_DEX_MEM_CANCEL,
IdentifierTemplate: hex.EncodeToString(dextypes.MemCancelPrefix(contractAddr)),
},
}

for _, order := range cancelOrdersMsg.GetCancellations() {
priceDenom := order.GetPriceDenom()
Expand Down
19 changes: 19 additions & 0 deletions aclmapping/utils/resource_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import (
aclsdktypes "github.com/cosmos/cosmos-sdk/types/accesscontrol"
acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
authztypes "github.com/cosmos/cosmos-sdk/x/authz/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
feegranttypes "github.com/cosmos/cosmos-sdk/x/feegrant"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
dextypes "github.com/sei-protocol/sei-chain/x/dex/types"
epochtypes "github.com/sei-protocol/sei-chain/x/epoch/types"
Expand Down Expand Up @@ -46,6 +49,10 @@ var StoreKeyToResourceTypePrefixMap = aclsdktypes.StoreKeyToResourceTypePrefixMa
// SETTLEMENT keys are prefixed with account and order id
aclsdktypes.ResourceType_KV_DEX_SETTLEMENT_ORDER_ID: aclsdktypes.EmptyPrefix,
aclsdktypes.ResourceType_KV_DEX_SETTLEMENT: aclsdktypes.EmptyPrefix,
// mem
aclsdktypes.ResourceType_KV_DEX_MEM_ORDER: dextypes.KeyPrefix(dextypes.MemOrderKey),
aclsdktypes.ResourceType_KV_DEX_MEM_CANCEL: dextypes.KeyPrefix(dextypes.MemCancelKey),
aclsdktypes.ResourceType_KV_DEX_MEM_DEPOSIT: dextypes.KeyPrefix(dextypes.MemDepositKey),
},
banktypes.StoreKey: {
aclsdktypes.ResourceType_KV_BANK: aclsdktypes.EmptyPrefix,
Expand All @@ -58,6 +65,9 @@ var StoreKeyToResourceTypePrefixMap = aclsdktypes.StoreKeyToResourceTypePrefixMa
aclsdktypes.ResourceType_KV_AUTH_ADDRESS_STORE: authtypes.AddressStoreKeyPrefix,
aclsdktypes.ResourceType_KV_AUTH_GLOBAL_ACCOUNT_NUMBER: authtypes.GlobalAccountNumberKey,
},
authztypes.StoreKey: {
aclsdktypes.ResourceType_KV_AUTHZ: aclsdktypes.EmptyPrefix,
},
distributiontypes.StoreKey: {
aclsdktypes.ResourceType_KV_DISTRIBUTION: aclsdktypes.EmptyPrefix,
aclsdktypes.ResourceType_KV_DISTRIBUTION_FEE_POOL: distributiontypes.FeePoolKey,
Expand All @@ -70,6 +80,10 @@ var StoreKeyToResourceTypePrefixMap = aclsdktypes.StoreKeyToResourceTypePrefixMa
aclsdktypes.ResourceType_KV_DISTRIBUTION_VAL_ACCUM_COMMISSION: distributiontypes.ValidatorAccumulatedCommissionPrefix,
aclsdktypes.ResourceType_KV_DISTRIBUTION_SLASH_EVENT: distributiontypes.ValidatorSlashEventPrefix,
},
feegranttypes.StoreKey: {
aclsdktypes.ResourceType_KV_FEEGRANT: aclsdktypes.EmptyPrefix,
aclsdktypes.ResourceType_KV_FEEGRANT_ALLOWANCE: feegranttypes.FeeAllowanceKeyPrefix,
},
oracletypes.StoreKey: {
aclsdktypes.ResourceType_KV_ORACLE: aclsdktypes.EmptyPrefix,
aclsdktypes.ResourceType_KV_ORACLE_VOTE_TARGETS: oracletypes.VoteTargetKey,
Expand Down Expand Up @@ -97,6 +111,11 @@ var StoreKeyToResourceTypePrefixMap = aclsdktypes.StoreKeyToResourceTypePrefixMa
aclsdktypes.ResourceType_KV_STAKING_VALIDATOR_QUEUE: stakingtypes.ValidatorQueueKey,
aclsdktypes.ResourceType_KV_STAKING_HISTORICAL_INFO: stakingtypes.HistoricalInfoKey,
},
slashingtypes.StoreKey: {
aclsdktypes.ResourceType_KV_SLASHING: aclsdktypes.EmptyPrefix,
aclsdktypes.ResourceType_KV_SLASHING_VAL_SIGNING_INFO: slashingtypes.ValidatorSigningInfoKeyPrefix,
aclsdktypes.ResourceType_KV_SLASHING_ADDR_PUBKEY_RELATION_KEY: slashingtypes.AddrPubkeyRelationKeyPrefix,
},
tokenfactorytypes.StoreKey: {
aclsdktypes.ResourceType_KV_TOKENFACTORY: aclsdktypes.EmptyPrefix,
aclsdktypes.ResourceType_KV_TOKENFACTORY_DENOM: []byte(tokenfactorytypes.DenomsPrefixKey),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ require (

replace (
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.376
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.377
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4
github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.1.132
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1067,8 +1067,8 @@ github.com/seccomp/libseccomp-golang v0.9.2-0.20210429002308-3879420cc921/go.mod
github.com/securego/gosec/v2 v2.11.0 h1:+PDkpzR41OI2jrw1q6AdXZCbsNGNGT7pQjal0H0cArI=
github.com/securego/gosec/v2 v2.11.0/go.mod h1:SX8bptShuG8reGC0XS09+a4H2BoWSJi+fscA+Pulbpo=
github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY=
github.com/sei-protocol/sei-cosmos v0.1.376 h1:94X4TWRK+wfq0BK7JRj+cu0Vx903EDiKBJVEG5NaIek=
github.com/sei-protocol/sei-cosmos v0.1.376/go.mod h1:lX+jDZ9u+afukL4Gc76YtKFEeCe9HfrAOCYAzSevAPw=
github.com/sei-protocol/sei-cosmos v0.1.377 h1:WGLoFwgvUOf30URiOTibeOBNwUvr0NkxezaP3nmPckg=
github.com/sei-protocol/sei-cosmos v0.1.377/go.mod h1:lX+jDZ9u+afukL4Gc76YtKFEeCe9HfrAOCYAzSevAPw=
github.com/sei-protocol/sei-tendermint v0.1.132 h1:bGzvArngcXgZ0PZSif2Qqp7p/YLd+fBxsYnH6Lqc0E4=
github.com/sei-protocol/sei-tendermint v0.1.132/go.mod h1:ubqjn2T/nvqmQYjgpOTV7uSyUvdfvJCepc7zNYL2mkw=
github.com/sei-protocol/sei-tm-db v0.0.5 h1:3WONKdSXEqdZZeLuWYfK5hP37TJpfaUa13vAyAlvaQY=
Expand Down
27 changes: 27 additions & 0 deletions parallelization/bank/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "bank"
version = "0.1.0"
edition = "2018"

[lib]
crate-type = ["cdylib", "rlib"]
doctest = false

[dependencies]
cosmwasm-std = { version = "1.0.0" }
cosmwasm-storage = { version = "1.0.0" }
cw-storage-plus = "0.13.2"
serde-json-wasm = "0.4.1"
cw2 = "0.13.2"
cw20 = "0.13.2"
schemars = "0.8.3"
serde = { version = "1.0.127", default-features = false, features = ["derive"] }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
thiserror = { version = "1.0.26" }
base64 = { version = "0.13.0" }

[dependencies.forward_ref]
version = "1"

[dev-dependencies]
cosmwasm-schema = { version = "1.0.0" }
26 changes: 26 additions & 0 deletions parallelization/bank/deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"wasm_dependency_mapping":
{
"enabled": true,
"contract_address": "sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m",
"access_ops": [
{
"operation": {
"access_type": "WRITE",
"resource_type": "KV_BANK_BALANCES",
"identifier_template": "02%s"
},
"selector_type": "JQ_LENGTH_PREFIXED_ADDRESS",
"selector": ".send.destination"
},
{
"operation": {
"access_type": "COMMIT",
"resource_type": "ANY",
"identifier_template": "*"
},
"selector_type": "NONE"
}
]
}
}
32 changes: 32 additions & 0 deletions parallelization/bank/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use cosmwasm_std::{
entry_point, BankMsg, DepsMut, Env, MessageInfo,
Response, StdError,
};
use crate::msg::{InstantiateMsg, ExecuteMsg};

#[entry_point]
pub fn instantiate(
_: DepsMut,
_env: Env,
_: MessageInfo,
_: InstantiateMsg,
) -> Result<Response, StdError> {
Ok(Response::default())
}

#[entry_point]
pub fn execute(
_: DepsMut,
_: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, StdError> {
match msg {
ExecuteMsg::Send { destination } => send(info, destination),
}
}

fn send(info: MessageInfo, destination: String) -> Result<Response, StdError> {
let msg = BankMsg::Send { to_address: destination, amount: info.funds };
Ok(Response::new().add_message(msg))
}
2 changes: 2 additions & 0 deletions parallelization/bank/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod contract;
pub mod msg;
13 changes: 13 additions & 0 deletions parallelization/bank/src/msg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, JsonSchema)]
pub struct InstantiateMsg {}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
Send {
destination: String,
},
}
27 changes: 27 additions & 0 deletions parallelization/staking/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "staking"
version = "0.1.0"
edition = "2018"

[lib]
crate-type = ["cdylib", "rlib"]
doctest = false

[dependencies]
cosmwasm-std = { version = "1.0.0", features = ["staking"] }
cosmwasm-storage = { version = "1.0.0" }
cw-storage-plus = "0.13.2"
serde-json-wasm = "0.4.1"
cw2 = "0.13.2"
cw20 = "0.13.2"
schemars = "0.8.3"
serde = { version = "1.0.127", default-features = false, features = ["derive"] }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
thiserror = { version = "1.0.26" }
base64 = { version = "0.13.0" }

[dependencies.forward_ref]
version = "1"

[dev-dependencies]
cosmwasm-schema = { version = "1.0.0" }
32 changes: 32 additions & 0 deletions parallelization/staking/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use cosmwasm_std::{
entry_point, StakingMsg, DepsMut, Env, MessageInfo,
Response, StdError,
};
use crate::msg::{InstantiateMsg, ExecuteMsg};

#[entry_point]
pub fn instantiate(
_: DepsMut,
_env: Env,
_: MessageInfo,
_: InstantiateMsg,
) -> Result<Response, StdError> {
Ok(Response::default())
}

#[entry_point]
pub fn execute(
_: DepsMut,
_: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, StdError> {
match msg {
ExecuteMsg::Delegate { validator } => delegate(info, validator),
}
}

fn delegate(info: MessageInfo, validator: String) -> Result<Response, StdError> {
let msg = StakingMsg::Delegate { validator: validator, amount: info.funds[0].clone() };
Ok(Response::new().add_message(msg))
}
2 changes: 2 additions & 0 deletions parallelization/staking/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod contract;
pub mod msg;
Loading