Skip to content

Commit

Permalink
[framework] Adds publisher module (#7196)
Browse files Browse the repository at this point in the history
Finalizes the experiment myself and @amnn started; and proposes a
`publisher` module.

The goal of this module is to enable recognition of the Publisher
authority. Potentially it could be used for:
1. Setting rules / registering a type in a system, such as metadata,
AFTER the module was published
2. Authorizing admin actions (effectively replacing AdminCap which is
often added manually)
  • Loading branch information
damirka authored Jan 12, 2023
1 parent e28585a commit 091949f
Show file tree
Hide file tree
Showing 8 changed files with 486 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ expression: common_costs_estimate
---
{
"MergeCoin": {
"computation_cost": 6847,
"storage_cost": 9817,
"computation_cost": 6942,
"storage_cost": 9958,
"storage_rebate": 0
},
"Publish": {
"computation_cost": 7652,
"storage_cost": 10939,
"computation_cost": 7802,
"storage_cost": 11161,
"storage_rebate": 0
},
"SharedCounterAssertValue": {
Expand All @@ -29,8 +29,8 @@ expression: common_costs_estimate
"storage_rebate": 0
},
"SplitCoin": {
"computation_cost": 6825,
"storage_cost": 9784,
"computation_cost": 6921,
"storage_cost": 9926,
"storage_rebate": 0
},
"TransferPortionSuiCoin": {
Expand Down
12 changes: 12 additions & 0 deletions crates/sui-framework/deps/move-stdlib/sources/address.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Provides a way to get address length since it's a
/// platform-specific parameter.
module std::address {
/// Should be converted to a native function.
/// Current implementation only works for Sui.
public fun length(): u64 {
20
}
}
50 changes: 49 additions & 1 deletion crates/sui-framework/deps/move-stdlib/sources/type_name.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

/// Functionality for converting Move types into values. Use with care!
module std::type_name {
use std::ascii::String;
use std::ascii::{Self, String};
use std::address;
use std::vector;

/// ASCII Character code for the `:` (colon) symbol.
const ASCII_COLON: u8 = 58;

struct TypeName has copy, drop, store {
/// String representation of the type. All types are represented
Expand All @@ -18,12 +23,55 @@ module std::type_name {

/// Return a value representation of the type `T`.
public native fun get<T>(): TypeName;
spec get {
pragma opaque;
}

/// Get the String representation of `self`
public fun borrow_string(self: &TypeName): &String {
&self.name
}

/// Get Address string (Base16 encoded), first part of the TypeName.
public fun get_address(self: &TypeName): String {
// Base16 (string) representation of an address has 2 symbols per byte.
let len = address::length() * 2;
let str_bytes = ascii::as_bytes(&self.name);
let addr_bytes = vector[];
let i = 0;

// Read `len` bytes from the type name and push them to addr_bytes.
while (i < len) {
vector::push_back(
&mut addr_bytes,
*vector::borrow(str_bytes, i)
);
i = i + 1;
};

ascii::string(addr_bytes)
}

/// Get name of the module.
public fun get_module(self: &TypeName): String {
// Starts after address and a double colon: `<addr as HEX>::`
let i = address::length() * 2 + 2;
let str_bytes = ascii::as_bytes(&self.name);
let module_name = vector[];

loop {
let char = vector::borrow(str_bytes, i);
if (char != &ASCII_COLON) {
vector::push_back(&mut module_name, *char);
i = i + 1;
} else {
break
}
};

ascii::string(module_name)
}

/// Convert `self` into its inner String
public fun into_string(self: TypeName): String {
self.name
Expand Down
14 changes: 2 additions & 12 deletions crates/sui-framework/docs/bcs.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,6 @@ For when bytes length is less than required for deserialization.



<a name="0x2_bcs_SUI_ADDRESS_LENGTH"></a>

Address length in Sui is 20 bytes.


<pre><code><b>const</b> <a href="bcs.md#0x2_bcs_SUI_ADDRESS_LENGTH">SUI_ADDRESS_LENGTH</a>: u64 = 20;
</code></pre>



<a name="0x2_bcs_to_bytes"></a>

## Function `to_bytes`
Expand Down Expand Up @@ -242,13 +232,13 @@ Read address from the bcs-serialized bytes.


<pre><code><b>public</b> <b>fun</b> <a href="bcs.md#0x2_bcs_peel_address">peel_address</a>(<a href="">bcs</a>: &<b>mut</b> <a href="bcs.md#0x2_bcs_BCS">BCS</a>): <b>address</b> {
<b>assert</b>!(v::length(&<a href="">bcs</a>.bytes) &gt;= <a href="bcs.md#0x2_bcs_SUI_ADDRESS_LENGTH">SUI_ADDRESS_LENGTH</a>, <a href="bcs.md#0x2_bcs_EOutOfRange">EOutOfRange</a>);
<b>assert</b>!(v::length(&<a href="">bcs</a>.bytes) &gt;= <a href="_length">address::length</a>(), <a href="bcs.md#0x2_bcs_EOutOfRange">EOutOfRange</a>);
<b>let</b> (addr_bytes, i) = (v::empty(), 0);
<b>while</b> (i &lt; 20) {
v::push_back(&<b>mut</b> addr_bytes, v::pop_back(&<b>mut</b> <a href="">bcs</a>.bytes));
i = i + 1;
};
<a href="address.md#0x2_address_from_bytes">address::from_bytes</a>(addr_bytes)
address::from_bytes(addr_bytes)
}
</code></pre>

Expand Down
2 changes: 1 addition & 1 deletion crates/sui-framework/docs/object.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Make an <code><a href="object.md#0x2_object_ID">ID</a></code> from raw bytes.


<pre><code><b>public</b> <b>fun</b> <a href="object.md#0x2_object_id_from_bytes">id_from_bytes</a>(bytes: <a href="">vector</a>&lt;u8&gt;): <a href="object.md#0x2_object_ID">ID</a> {
<a href="object.md#0x2_object_id_from_address">id_from_address</a>(<a href="address.md#0x2_address_from_bytes">address::from_bytes</a>(bytes))
<a href="object.md#0x2_object_id_from_address">id_from_address</a>(address::from_bytes(bytes))
}
</code></pre>

Expand Down
Loading

1 comment on commit 091949f

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Owned Transactions Benchmark Results

Benchmark Report:
+-------------+-----+--------+-----+-----+-----+-----+-----+-----+-------+-----+
| duration(s) | tps | error% | min | p25 | p50 | p75 | p90 | p99 | p99.9 | max |
+==============================================================================+
| 60          | 100 | 0      | 12  | 22  | 58  | 60  | 95  | 103 | 105   | 106 |

Shared Transactions Benchmark Results

Benchmark Report:
+-------------+-----+--------+-----+-----+-----+-----+-----+------+-------+------+
| duration(s) | tps | error% | min | p25 | p50 | p75 | p90 | p99  | p99.9 | max  |
+================================================================================+
| 60          | 99  | 0      | 16  | 434 | 531 | 622 | 693 | 1035 | 1336  | 1439 |

Narwhal Benchmark Results

 SUMMARY:
-----------------------------------------
 + CONFIG:
 Faults: 0 node(s)
 Committee size: 4 node(s)
 Worker(s) per node: 1 worker(s)
 Collocate primary and workers: True
 Input rate: 50,000 tx/s
 Transaction size: 512 B
 Execution time: 58 s

 Header number of batches threshold: 32 digests
 Header maximum number of batches: 1,000 digests
 Max header delay: 2,000 ms
 GC depth: 50 round(s)
 Sync retry delay: 10,000 ms
 Sync retry nodes: 3 node(s)
 batch size: 500,000 B
 Max batch delay: 200 ms
 Max concurrent requests: 500,000 

 + RESULTS:
 Batch creation avg latency: 77 ms
 Header creation avg latency: 1,742 ms
 	Batch to header avg latency: 947 ms
 Header to certificate avg latency: 7 ms
 	Request vote outbound avg latency: 3 ms
 Certificate commit avg latency: 3,123 ms

 Consensus TPS: 49,499 tx/s
 Consensus BPS: 25,343,556 B/s
 Consensus latency: 3,230 ms

 End-to-end TPS: 47,830 tx/s
 End-to-end BPS: 24,488,810 B/s
 End-to-end latency: 4,218 ms
-----------------------------------------

Please sign in to comment.