Module 0x1::jwk_consensus_config
Structs and functions related to JWK consensus configurations.
- Resource
JWKConsensusConfig - Struct
ConfigOff - Struct
OIDCProvider - Struct
ConfigV1 - Constants
- Function
initialize - Function
set_for_next_epoch - Function
on_new_epoch - Function
new_off - Function
new_v1 - Function
new_oidc_provider - Specification
use 0x1::config_buffer;
use 0x1::copyable_any;
use 0x1::error;
use 0x1::option;
use 0x1::simple_map;
use 0x1::string;
use 0x1::system_addresses;
Resource JWKConsensusConfig
The configuration of the JWK consensus feature.
struct JWKConsensusConfig has drop, store, key
Fields
-
variant: copyable_any::Any -
A config variant packed as an
Any. Currently the variant type is one of the following. -ConfigOff-ConfigV1
Struct ConfigOff
A JWK consensus config variant indicating JWK consensus should not run.
struct ConfigOff has copy, drop, store
Fields
-
dummy_field: bool
Struct OIDCProvider
struct OIDCProvider has copy, drop, store
Fields
-
name: string::String -
config_url: string::String
Struct ConfigV1
A JWK consensus config variant indicating JWK consensus should run to watch a given list of OIDC providers.
struct ConfigV1 has copy, drop, store
Fields
-
oidc_providers: vector<jwk_consensus_config::OIDCProvider>
Constants
ConfigV1 creation failed with duplicated providers given.
const EDUPLICATE_PROVIDERS: u64 = 1;
Function initialize
Initialize the configuration. Used in genesis or governance.
public fun initialize(framework: &signer, config: jwk_consensus_config::JWKConsensusConfig)
Implementation
public fun initialize(framework: &signer, config: JWKConsensusConfig) {
system_addresses::assert_aptos_framework(framework);
if (!exists<JWKConsensusConfig>(@aptos_framework)) {
move_to(framework, config);
}
}
Function set_for_next_epoch
This can be called by on-chain governance to update JWK consensus configs for the next epoch. Example usage:
use aptos_framework::jwk_consensus_config;
use aptos_framework::aptos_governance;
// ...
let config = jwk_consensus_config::new_v1(vector[]);
jwk_consensus_config::set_for_next_epoch(&framework_signer, config);
aptos_governance::reconfigure(&framework_signer);
public fun set_for_next_epoch(framework: &signer, config: jwk_consensus_config::JWKConsensusConfig)
Implementation
public fun set_for_next_epoch(framework: &signer, config: JWKConsensusConfig) {
system_addresses::assert_aptos_framework(framework);
config_buffer::upsert(config);
}
Function on_new_epoch
Only used in reconfigurations to apply the pending JWKConsensusConfig, if there is any.
public(friend) fun on_new_epoch(framework: &signer)
Implementation
public(friend) fun on_new_epoch(framework: &signer) acquires JWKConsensusConfig {
system_addresses::assert_aptos_framework(framework);
if (config_buffer::does_exist<JWKConsensusConfig>()) {
let new_config = config_buffer::extract_v2<JWKConsensusConfig>();
if (exists<JWKConsensusConfig>(@aptos_framework)) {
*borrow_global_mut<JWKConsensusConfig>(@aptos_framework) = new_config;
} else {
move_to(framework, new_config);
};
}
}
Function new_off
Construct a JWKConsensusConfig of variant ConfigOff.
public fun new_off(): jwk_consensus_config::JWKConsensusConfig
Implementation
public fun new_off(): JWKConsensusConfig {
JWKConsensusConfig {
variant: copyable_any::pack( ConfigOff {} )
}
}
Function new_v1
Construct a JWKConsensusConfig of variant ConfigV1.
Abort if the given provider list contains duplicated provider names.
public fun new_v1(oidc_providers: vector<jwk_consensus_config::OIDCProvider>): jwk_consensus_config::JWKConsensusConfig
Implementation
public fun new_v1(oidc_providers: vector<OIDCProvider>): JWKConsensusConfig {
let name_set = simple_map::new<String, u64>();
oidc_providers.for_each_ref(|provider| {
let provider: &OIDCProvider = provider;
let (_, old_value) = simple_map::upsert(&mut name_set, provider.name, 0);
if (option::is_some(&old_value)) {
abort(error::invalid_argument(EDUPLICATE_PROVIDERS))
}
});
JWKConsensusConfig {
variant: copyable_any::pack( ConfigV1 { oidc_providers } )
}
}
Function new_oidc_provider
Construct an OIDCProvider object.
public fun new_oidc_provider(name: string::String, config_url: string::String): jwk_consensus_config::OIDCProvider
Implementation
public fun new_oidc_provider(name: String, config_url: String): OIDCProvider {
OIDCProvider { name, config_url }
}
Specification
Function on_new_epoch
public(friend) fun on_new_epoch(framework: &signer)
requires @aptos_framework == std::signer::address_of(framework);
include config_buffer::OnNewEpochRequirement<JWKConsensusConfig>;
aborts_if false;