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

Update for Paseo support #187

Merged
merged 2 commits into from
Mar 27, 2024
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: 3 additions & 2 deletions bridge/common/protos/output.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ message Config {

enum EnvironmentType {
MainNet = 0;
Rococo = 1;
Dev = 2;
TestnetPaseo = 1;
Rococo = 2;
Dev = 3;
}

message Environment {
Expand Down
319 changes: 163 additions & 156 deletions bridge/common/src/proto_types/output.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions bridge/ffi/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ pub struct Config {
pub enum Environment {
Mainnet,
Rococo,
TestnetPaseo,
Dev(Config),
}

Expand Down
6 changes: 5 additions & 1 deletion bridge/ffi/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::bindings::*;
use dsnp_graph_config::{Config as RustConfig, DsnpVersion, MAINNET_CONFIG, ROCOCO_CONFIG};
use dsnp_graph_config::{
Config as RustConfig, DsnpVersion, MAINNET_CONFIG, ROCOCO_CONFIG, TESTNET_PASEO_CONFIG,
};
use std::{collections::HashMap, mem::ManuallyDrop};

pub fn get_config_for_ffi(environment: &Environment) -> Config {
match environment {
Environment::Mainnet => get_config_from_rust_config(&MAINNET_CONFIG),
Environment::Rococo => get_config_from_rust_config(&ROCOCO_CONFIG),
Environment::TestnetPaseo => get_config_from_rust_config(&TESTNET_PASEO_CONFIG),
Environment::Dev(config) => config.clone(),
}
}
Expand Down Expand Up @@ -82,6 +85,7 @@ pub fn environment_from_ffi(environment: &Environment) -> dsnp_graph_config::Env
match environment {
Environment::Mainnet => dsnp_graph_config::Environment::Mainnet,
Environment::Rococo => dsnp_graph_config::Environment::Rococo,
Environment::TestnetPaseo => dsnp_graph_config::Environment::TestnetPaseo,
Environment::Dev(config) => {
let rust_config = config_from_ffi(config);
dsnp_graph_config::Environment::Dev(rust_config)
Expand Down
1 change: 1 addition & 0 deletions bridge/jni/src/mappings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub fn map_to_environment(
{
proto_output::EnvironmentType::MainNet => RustEnvironment::Mainnet,
proto_output::EnvironmentType::Rococo => RustEnvironment::Rococo,
proto_output::EnvironmentType::TestnetPaseo => RustEnvironment::TestnetPaseo,
proto_output::EnvironmentType::Dev => {
let cfg = env_proto
.config
Expand Down
10 changes: 10 additions & 0 deletions bridge/node/js/graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ describe("Graph tests", () => {
expect(schema_id).toEqual(8);
graph.freeGraphState();
});

test("getGraphConfig with Testnet Paseo environment should return the graph config", async () => {
const environment: EnvironmentInterface = {
environmentType: EnvironmentType.TestnetPaseo,
};
const graph = new Graph(environment);
const config = graph.getGraphConfig(environment);
expect(config).toBeDefined();
graph.freeGraphState();
});

test("getGraphConfig with Rococo environment should return the graph config", async () => {
const environment: EnvironmentInterface = {
Expand Down
11 changes: 3 additions & 8 deletions bridge/node/js/models/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Config } from "./config";

enum EnvironmentType {
Mainnet = "Mainnet",
TestnetPaseo = "TestnetPaseo",
Rococo = "Rococo",
Dev = "Dev",
}
Expand All @@ -11,7 +12,7 @@ interface EnvironmentInterface {
}

interface Environment extends EnvironmentInterface {
environmentType: EnvironmentType.Mainnet | EnvironmentType.Rococo;
environmentType: EnvironmentType.Mainnet | EnvironmentType.Rococo | EnvironmentType.TestnetPaseo;
}

interface DevEnvironment extends EnvironmentInterface {
Expand All @@ -21,10 +22,4 @@ interface DevEnvironment extends EnvironmentInterface {

type EnvironmentConfig = DevEnvironment;

export {
EnvironmentType,
Environment,
DevEnvironment,
EnvironmentConfig,
EnvironmentInterface,
};
export { EnvironmentType, Environment, DevEnvironment, EnvironmentConfig, EnvironmentInterface };
1 change: 1 addition & 0 deletions bridge/node/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub unsafe fn environment_from_js(
match environment_type_str.value(cx).as_str() {
"Mainnet" => Ok(Environment::Mainnet),
"Rococo" => Ok(Environment::Rococo),
"TestnetPaseo" => Ok(Environment::TestnetPaseo),
"Dev" => {
let config: Handle<JsObject> = environment_from_js.get(cx, "config").unwrap();
let config = config_from_js(cx, config)?;
Expand Down
6 changes: 4 additions & 2 deletions config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ All of different settings and configuration parameters are encapsulated inside t
#### Supported `Environments` and their corresponding configurations:
- `Mainnet`: This environment corresponds to the **production** settings. It is used for live deployments and real-world
usage.
- `Rococo`: This environment represents the **staging** settings. It is typically used for pre-production testing and
validation before deployment to the production environment.
- `TestnetPaseo`: This environment represents **staging** settings. It is typically used for pre-production testing and
validation before deployment to the production environment.
- `Rococo`: This environment represents **staging** settings. It is typically used for pre-production testing and
validation before deployment to the production environment.
- `Dev`: This environment is specifically designed for **local** development and testing purposes. It allows
developers to experiment and iterate on their code locally without affecting the production or staging environments.

Expand Down
41 changes: 41 additions & 0 deletions config/resources/configs/frequency-testnet-paseo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"sdkMaxUsersGraphSize": 10000,
"sdkMaxStaleFriendshipDays": 90,
"maxGraphPageSizeBytes": 1024,
"maxPageId": 16,
"maxKeyPageSizeBytes": 65536,
"graphPublicKeySchemaId": 7,
"schemaMap": [
[
8,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to make sure that these schema id's are the same as what we registered on paseo for each

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are. Here's the output of the deploy script:

Generated schema mapping:
 {
  "0x203c6838fc78ea3660a2f298a58d859519c72a5efdc0f194abd6f0d5ce1838e0": {
    "tombstone": {
      "1.2": 1
    },
    "broadcast": {
      "1.2": 2
    },
    "reply": {
      "1.2": 3
    },
    "reaction": {
      "1.1": 4
    },
    "profile": {
      "1.2": 5
    },
    "update": {
      "1.2": 6
    },
    "public-key-key-agreement": {
      "1.2": 7
    },
    "public-follows": {
      "1.2": 8
    },
    "private-follows": {
      "1.2": 9
    },
    "private-connections": {
      "1.2": 10
    },
    "public-key-assertion-method": {
      "1.3": 11
    }
  }
}

[
"1.0",
{
"connectionType": "follow",
"privacyType": "public"
}
]
],
[
9,
[
"1.0",
{
"connectionType": "follow",
"privacyType": "private"
}
]
],
[
10,
[
"1.0",
{
"connectionType": "friendship",
"privacyType": "private"
}
]
]
],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the paseo schema 10 does not have any settings , expecting signature required setting on it ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with schema 9 it has setting set to 0 , I think private schemas require signatures enforcement

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schema 8 is good it's Avro Paginated and setting=0

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think schema 7 has setting = 3 not sure if it corresponds to AppendOnly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the same settings as appear on mainnet. So if they are wrong, so is mainnet 😟

Copy link
Collaborator

@saraswatpuneet saraswatpuneet Mar 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think they are wrong "in spirit" meaning most stateful operations everywhere is only calling "upsert_page" extrinsic and it does not check for schema permission but extrinsics with "...._with_signature" might be misleading

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its, fine but any application that enforces signature permission on schemas should know, not to use the ones in this config,

https://github.com/LibertyDSNP/frequency/blob/9b948d72751839e516791a4cb3ee216985554963/pallets/stateful-storage/src/lib.rs#L770C47-L770C64

"dsnpVersions": ["1.0"]
}
8 changes: 7 additions & 1 deletion config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ lazy_static! {
/// Mainnet `Config`
pub static ref MAINNET_CONFIG: Config = include_str!("../resources/configs/frequency.json")
.try_into().unwrap();
/// Rococo `Config`
/// Testnet Rococo `Config`
pub static ref ROCOCO_CONFIG: Config = include_str!("../resources/configs/frequency-rococo.json")
.try_into().unwrap();
/// Testnet Paseo `Config`
pub static ref TESTNET_PASEO_CONFIG: Config = include_str!("../resources/configs/frequency-testnet-paseo.json")
.try_into().unwrap();
}

/// Privacy Type of the graph
Expand Down Expand Up @@ -121,6 +124,7 @@ pub enum GraphKeyType {
pub enum Environment {
Mainnet,
Rococo,
TestnetPaseo,
Dev(Config),
}

Expand All @@ -130,6 +134,7 @@ impl Environment {
match self {
Environment::Mainnet => &MAINNET_CONFIG,
Environment::Rococo => &ROCOCO_CONFIG,
Environment::TestnetPaseo => &TESTNET_PASEO_CONFIG,
Environment::Dev(cfg) => &cfg,
}
}
Expand Down Expand Up @@ -320,6 +325,7 @@ mod config_tests {
fn lazy_static_configs_are_valid() -> Result<(), apache_avro::Error> {
let _ = MAINNET_CONFIG;
let _ = ROCOCO_CONFIG;
let _ = TESTNET_PASEO_CONFIG;
Ok(())
}
}
8 changes: 8 additions & 0 deletions java/lib/src/main/java/io/amplica/graphsdk/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
public class Configuration {
private static Configuration MAIN_NET_INSTANCE;
private static Configuration ROCOCO_INSTANCE;
private static Configuration TESTNET_PASEO_INSTANCE;

private final Config inner;
private final Environment environment;
Expand Down Expand Up @@ -55,6 +56,13 @@ public static Configuration getMainNet() throws InvalidProtocolBufferException {
return MAIN_NET_INSTANCE;
}

public static Configuration getTestnetPaseo() throws InvalidProtocolBufferException {
if(TESTNET_PASEO_INSTANCE == null) {
TESTNET_PASEO_INSTANCE = new Configuration(EnvironmentType.TestnetPaseo);
}
return TESTNET_PASEO_INSTANCE;
}

public static Configuration getRococo() throws InvalidProtocolBufferException {
if(ROCOCO_INSTANCE == null) {
ROCOCO_INSTANCE = new Configuration(EnvironmentType.Rococo);
Expand Down

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

7 changes: 4 additions & 3 deletions java/lib/src/main/java/io/amplica/graphsdk/models/Output.java

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

10 changes: 10 additions & 0 deletions java/lib/src/test/java/io/amplica/graphsdk/LibraryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ void initiate_main_net_state_should_work() throws Exception {
graph.finalize();
}

@Test
void initiate_testnet_paseo_state_should_work() throws Exception {
// act
var graph = new Graph(Configuration.getTestnetPaseo());

// assert
assertNotEquals(0, graph.unsafeNativeHandleWithoutGuard());
graph.finalize();
}

@Test
void initiate_rococo_state_should_work() throws Exception {
// act
Expand Down
Loading