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

feat: blocked addrs #73

Merged
merged 6 commits into from
Jun 19, 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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Install latest rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: 1.77.1
components: rustfmt, clippy
- uses: actions/setup-go@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Install latest rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: 1.77.1
- uses: actions/setup-go@v4
with:
go-version: "1.22"
Expand Down
1 change: 1 addition & 0 deletions api/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ typedef struct {
uint64_t*,
uint64_t*,
uint8_t*,
bool*,
UnmanagedVector*);
int32_t (*amount_to_share)(const api_t*,
U8SliceView,
Expand Down
11 changes: 6 additions & 5 deletions api/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ typedef GoError (*remove_db_fn)(db_t *ptr, U8SliceView key, UnmanagedVector *err
typedef GoError (*scan_db_fn)(db_t *ptr, U8SliceView prefix, U8SliceView start, U8SliceView end, int32_t order, GoIter *out, UnmanagedVector *errOut);
// and api
typedef GoError (*query_fn)(api_t *ptr, U8SliceView request, uint64_t gasBalance, UnmanagedVector *response, uint64_t *usedGas, UnmanagedVector *errOut);
typedef GoError (*get_account_info_fn)(api_t *ptr, U8SliceView addr, bool *found, uint64_t *account_number, uint64_t *sequence, uint8_t *account_type, UnmanagedVector *errOut);
typedef GoError (*get_account_info_fn)(api_t *ptr, U8SliceView addr, bool *found, uint64_t *account_number, uint64_t *sequence, uint8_t *account_type, bool *is_blocked, UnmanagedVector *errOut);
typedef GoError (*amount_to_share_fn)(api_t *ptr, U8SliceView validator, U8SliceView metadata, uint64_t amount, uint64_t *share, UnmanagedVector *errOut);
typedef GoError (*share_to_amount_fn)(api_t *ptr, U8SliceView validator, U8SliceView metadata, uint64_t share, uint64_t *amount, UnmanagedVector *errOut);
typedef GoError (*unbond_timestamp_fn)(api_t *ptr, uint64_t *unbondTimestamp, UnmanagedVector *errOut);
Expand All @@ -28,7 +28,7 @@ GoError cDelete_cgo(db_t *ptr, U8SliceView key, UnmanagedVector *errOut);
GoError cScan_cgo(db_t *ptr, U8SliceView prefix, U8SliceView start, U8SliceView end, int32_t order, GoIter *out, UnmanagedVector *errOut);
// api
GoError cQuery_cgo(api_t *ptr, U8SliceView request, uint64_t gasBalance, UnmanagedVector *response, uint64_t *usedGas, UnmanagedVector *errOut);
GoError cGetAccountInfo_cgo(api_t *ptr, U8SliceView addr, bool *found, uint64_t *account_number, uint64_t *sequence, uint8_t *account_type, UnmanagedVector *errOut);
GoError cGetAccountInfo_cgo(api_t *ptr, U8SliceView addr, bool *found, uint64_t *account_number, uint64_t *sequence, uint8_t *account_type, bool *is_blocked, UnmanagedVector *errOut);
GoError cAmountToShare_cgo(api_t *ptr, U8SliceView validator, U8SliceView metadata, uint64_t amount, uint64_t *share, UnmanagedVector *errOut);
GoError cShareToAmount_cgo(api_t *ptr, U8SliceView validator, U8SliceView metadata, uint64_t share, uint64_t *amount, UnmanagedVector *errOut);
GoError cUnbondTimestamp_cgo(api_t *ptr, uint64_t *unbondTimestamp, UnmanagedVector *errOut);
Expand Down Expand Up @@ -302,7 +302,7 @@ func cNext(ref C.iterator_t, key *C.UnmanagedVector, errOut *C.UnmanagedVector)

type GoAPI interface {
Query(types.QueryRequest, uint64) ([]byte, uint64, error)
GetAccountInfo(types.AccountAddress) (bool /* found */, uint64 /* account number */, uint64 /* sequence */, uint8 /* account type */)
GetAccountInfo(types.AccountAddress) (bool /* found */, uint64 /* account number */, uint64 /* sequence */, uint8 /* account type */, bool /* is blocked */)
AmountToShare([]byte, types.AccountAddress, uint64) (uint64, error)
ShareToAmount([]byte, types.AccountAddress, uint64) (uint64, error)
UnbondTimestamp() uint64
Expand Down Expand Up @@ -360,7 +360,7 @@ func cQuery(ptr *C.api_t, request C.U8SliceView, gasBalance C.uint64_t, response
}

//export cGetAccountInfo
func cGetAccountInfo(ptr *C.api_t, addr C.U8SliceView, found *C.bool, account_number *C.uint64_t, sequence *C.uint64_t, account_type *C.uint8_t, errOut *C.UnmanagedVector) (ret C.GoError) {
func cGetAccountInfo(ptr *C.api_t, addr C.U8SliceView, found *C.bool, account_number *C.uint64_t, sequence *C.uint64_t, account_type *C.uint8_t, is_blocked *C.bool, errOut *C.UnmanagedVector) (ret C.GoError) {
defer recoverPanic(&ret)

if found == nil {
Expand Down Expand Up @@ -391,11 +391,12 @@ func cGetAccountInfo(ptr *C.api_t, addr C.U8SliceView, found *C.bool, account_nu
return C.GoError_User
}

f, an, seq, accType := api.GetAccountInfo(accAddr)
f, an, seq, accType, isBlocked := api.GetAccountInfo(accAddr)
*found = C.bool(f)
*account_number = C.uint64_t(an)
*sequence = C.uint64_t(seq)
*account_type = C.uint8_t(accType)
*is_blocked = C.bool(isBlocked)

return C.GoError_None
}
Expand Down
6 changes: 3 additions & 3 deletions api/callbacks_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GoError cDelete(db_t *ptr, U8SliceView key, UnmanagedVector *errOut);
GoError cScan(db_t *ptr, U8SliceView prefix, U8SliceView start, U8SliceView end, int32_t order, GoIter *out, UnmanagedVector *errOut);
// imports (api)
GoError cQuery(api_t *ptr, U8SliceView request, uint64_t gasBalance, UnmanagedVector *response, uint64_t *usedGas, UnmanagedVector *errOut);
GoError cGetAccountInfo(api_t *ptr, U8SliceView addr, bool *found, uint64_t *account_number, uint64_t *sequence, uint8_t *account_type, UnmanagedVector *errOut);
GoError cGetAccountInfo(api_t *ptr, U8SliceView addr, bool *found, uint64_t *account_number, uint64_t *sequence, uint8_t *account_type, bool *is_blocked, UnmanagedVector *errOut);
GoError cAmountToShare(api_t *ptr, U8SliceView validator, U8SliceView metadata, uint64_t amount, uint64_t *share, UnmanagedVector *errOut);
GoError cShareToAmount(api_t *ptr, U8SliceView validator, U8SliceView metadata, uint64_t share, uint64_t *amount, UnmanagedVector *errOut);
GoError cUnbondTimestamp(api_t *ptr, uint64_t *unbondTimestamp, UnmanagedVector *errOut);
Expand Down Expand Up @@ -42,8 +42,8 @@ GoError cNext_cgo(iterator_t *ptr, UnmanagedVector *key, UnmanagedVector *errOut
GoError cQuery_cgo(api_t *ptr, U8SliceView request, uint64_t gasBalance, UnmanagedVector *response, uint64_t *usedGas, UnmanagedVector *errOut) {
return cQuery(ptr, request, gasBalance, response, usedGas, errOut);
}
GoError cGetAccountInfo_cgo(api_t *ptr, U8SliceView addr, bool *found, uint64_t *account_number, uint64_t *sequence, uint8_t *account_type, UnmanagedVector *errOut) {
return cGetAccountInfo(ptr, addr, found, account_number, sequence, account_type, errOut);
GoError cGetAccountInfo_cgo(api_t *ptr, U8SliceView addr, bool *found, uint64_t *account_number, uint64_t *sequence, uint8_t *account_type, bool *is_blocked, UnmanagedVector *errOut) {
return cGetAccountInfo(ptr, addr, found, account_number, sequence, account_type, is_blocked, errOut);
}
GoError cAmountToShare_cgo(api_t *ptr, U8SliceView validator, U8SliceView coinType, uint64_t amount, uint64_t *share, UnmanagedVector *errOut) {
return cAmountToShare(ptr, validator, coinType, amount, share, errOut);
Expand Down
8 changes: 4 additions & 4 deletions api/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (m MockAPI) Query(request types.QueryRequest, gasBalance uint64) ([]byte, u
return m.QueryAPI.Query(request, gasBalance)
}

func (m MockAPI) GetAccountInfo(addr types.AccountAddress) (bool, uint64, uint64, uint8) {
func (m MockAPI) GetAccountInfo(addr types.AccountAddress) (bool, uint64, uint64, uint8, bool) {
Copy link

Choose a reason for hiding this comment

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

The updated return values of GetAccountInfo correctly include the is_blocked status. Ensure there are unit tests covering scenarios where an account is blocked and not blocked.

Would you like me to help create these unit tests?

Also applies to: 156-162

return m.AccountAPI.GetAccountInfo(addr)
}

Expand Down Expand Up @@ -153,13 +153,13 @@ func (m *MockAccountAPI) SetAccountInfo(addr types.AccountAddress, accountNumber
m.accounts[addr.String()] = []uint64{accountNumber, sequence, uint64(accountType)}
}

func (m MockAccountAPI) GetAccountInfo(addr types.AccountAddress) (bool, uint64, uint64, uint8) {
func (m MockAccountAPI) GetAccountInfo(addr types.AccountAddress) (bool, uint64, uint64, uint8, bool) {
info, found := m.accounts[addr.String()]
if found {
return found, info[0], info[1], uint8(info[2])
return found, info[0], info[1], uint8(info[2]), false
}

return false, 0, 0, 0
return false, 0, 0, 0, false
}

type ShareAmountRatio struct {
Expand Down
3 changes: 2 additions & 1 deletion crates/compiler/src/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ impl AccountAPI for BlankAccountAPIImpl {
u64, /* account_number */
u64, /* sequence */
u8, /* account_type */
bool, /* is_blocked */
)> {
Ok((false, 0, 0, 0))
Ok((false, 0, 0, 0, false))
}
}

Expand Down
18 changes: 11 additions & 7 deletions crates/e2e-move-tests/src/test_utils/mock_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ impl AccountAPI for MockAPI {
u64, /* account_number */
u64, /* sequence */
u8, /* account_type */
bool, /* is_blocked */
)> {
self.account_api.get_account_info(addr)
}
Expand Down Expand Up @@ -305,7 +306,7 @@ impl OracleAPI for MockAPI {
}

pub struct MockAccountAPI {
pub accounts: BTreeMap<AccountAddress, (u64, u64, u8)>,
pub accounts: BTreeMap<AccountAddress, (u64, u64, u8, bool)>,
}

impl MockAccountAPI {
Expand All @@ -321,18 +322,20 @@ impl MockAccountAPI {
account_number: u64,
sequence: u64,
account_type: u8,
is_blocked: bool,
) {
self.accounts
.insert(addr, (account_number, sequence, account_type));
.insert(addr, (account_number, sequence, account_type, is_blocked));
}
}

impl MockAccountAPI {
fn get_account_info(&self, addr: AccountAddress) -> anyhow::Result<(bool, u64, u64, u8)> {
if let Some((account_number, sequence, account_type)) = self.accounts.get(&addr) {
Ok((true, *account_number, *sequence, *account_type))
fn get_account_info(&self, addr: AccountAddress) -> anyhow::Result<(bool, u64, u64, u8, bool)> {
if let Some((account_number, sequence, account_type, is_blocked)) = self.accounts.get(&addr)
{
Ok((true, *account_number, *sequence, *account_type, *is_blocked))
} else {
Ok((false, 0, 0, 0))
Ok((false, 0, 0, 0, false))
}
}
}
Expand Down Expand Up @@ -552,8 +555,9 @@ impl AccountAPI for BlankAccountAPIImpl {
u64, /* account_number */
u64, /* sequence */
u8, /* account_ype */
bool, /* is_blocked */
)> {
Ok((false, 0, 0, 0))
Ok((false, 0, 0, 0, false))
}
}

Expand Down
29 changes: 18 additions & 11 deletions crates/natives/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub trait AccountAPI {
u64, /* account_number */
u64, /* sequence_number */
u8, /* account_type */
bool, /* is_blocked */
)>;
}

Expand All @@ -49,9 +50,10 @@ pub struct NativeAccountContext<'a> {
test_accounts: BTreeMap<
AccountAddress,
(
u64, /* account_number */
u64, /* sequence */
u8, /* account_type */
u64, /* account_number */
u64, /* sequence */
u8, /* account_type */
bool, /* is_blocked */
),
>,
}
Expand Down Expand Up @@ -84,9 +86,10 @@ impl<'a> NativeAccountContext<'a> {
account_number: u64,
sequence: u64,
account_type: u8,
is_blocked: bool,
) {
self.test_accounts
.insert(addr, (account_number, sequence, account_type));
.insert(addr, (account_number, sequence, account_type, is_blocked));
}
}

Expand Down Expand Up @@ -115,19 +118,20 @@ fn native_get_account_info(

let address = safely_pop_arg!(arguments, AccountAddress);
let account_context = context.extensions().get::<NativeAccountContext>();
let (found, account_number, sequence, account_type) =
let (found, account_number, sequence, account_type, is_blocked) =
if let Some(new_account) = account_context.new_accounts.get(&address) {
(true, new_account.0, 0, new_account.1)
(true, new_account.0, 0, new_account.1, false)
} else {
#[cfg(feature = "testing")]
if let Some((account_number, sequence, account_type)) =
if let Some((account_number, sequence, account_type, is_blocked)) =
account_context.test_accounts.get(&address)
{
return Ok(smallvec![
Value::bool(true),
Value::u64(*account_number),
Value::u64(*sequence),
Value::u8(*account_type)
Value::u8(*account_type),
Value::bool(*is_blocked),
]);
}

Expand All @@ -149,7 +153,8 @@ fn native_get_account_info(
Value::bool(found),
Value::u64(account_number),
Value::u64(sequence),
Value::u8(account_type)
Value::u8(account_type),
Value::bool(is_blocked)
])
}

Expand Down Expand Up @@ -270,7 +275,7 @@ pub fn make_all(
) -> impl Iterator<Item = (String, NativeFunction)> + '_ {
let mut natives = vec![];
natives.extend([
("get_account_info", native_get_account_info as RawSafeNative),
("account_info", native_get_account_info as RawSafeNative),
("request_create_account", native_create_account),
("create_address", native_create_address),
("create_signer", native_create_signer),
Expand All @@ -292,8 +297,9 @@ fn native_test_only_set_account_info(
mut arguments: VecDeque<Value>,
) -> SafeNativeResult<SmallVec<[Value; 1]>> {
debug_assert!(ty_args.is_empty());
debug_assert!(arguments.len() == 4);
debug_assert!(arguments.len() == 5);

let is_blocked = safely_pop_arg!(arguments, bool);
let account_type = safely_pop_arg!(arguments, u8);
let sequence = safely_pop_arg!(arguments, u64);
let account_number = safely_pop_arg!(arguments, u64);
Expand All @@ -306,6 +312,7 @@ fn native_test_only_set_account_info(
account_number,
sequence,
account_type,
is_blocked,
);

Ok(smallvec![])
Expand Down
1 change: 1 addition & 0 deletions libmovevm/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ typedef struct {
uint64_t*,
uint64_t*,
uint8_t*,
bool*,
UnmanagedVector*);
int32_t (*amount_to_share)(const api_t*,
U8SliceView,
Expand Down
7 changes: 5 additions & 2 deletions libmovevm/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct GoApi_vtable {
*mut u64, // account_number
*mut u64, // sequence
*mut u8, // account_type
*mut bool, // is_blocked
*mut UnmanagedVector, // error_msg
) -> i32,
pub amount_to_share: extern "C" fn(
Expand Down Expand Up @@ -83,7 +84,7 @@ unsafe impl Send for GoApi {}

impl AccountAPI for GoApi {
// return latest block height and timestamp
fn get_account_info(&self, addr: AccountAddress) -> anyhow::Result<(bool, u64, u64, u8)> {
fn get_account_info(&self, addr: AccountAddress) -> anyhow::Result<(bool, u64, u64, u8, bool)> {
// DO NOT DELETE; same reason with KeepAlive in go
let addr_bytes = addr.into_bytes();

Expand All @@ -92,6 +93,7 @@ impl AccountAPI for GoApi {
let mut account_number = 0_u64;
let mut sequence = 0_u64;
let mut account_type: u8 = 0_u8;
let mut is_blocked = false;
let mut error_msg = UnmanagedVector::default();

let go_error: GoError = (self.vtable.get_account_info)(
Expand All @@ -101,6 +103,7 @@ impl AccountAPI for GoApi {
&mut account_number as *mut u64,
&mut sequence as *mut u64,
&mut account_type as *mut u8,
&mut is_blocked as *mut bool,
&mut error_msg as *mut UnmanagedVector,
)
.into();
Expand All @@ -113,7 +116,7 @@ impl AccountAPI for GoApi {
}
}

Ok((found, account_number, sequence, account_type))
Ok((found, account_number, sequence, account_type, is_blocked))
}
}

Expand Down
Binary file modified precompile/binaries/minlib/account.mv
Binary file not shown.
Binary file modified precompile/binaries/minlib/coin.mv
Binary file not shown.
Binary file modified precompile/binaries/minlib/fungible_asset.mv
Binary file not shown.
Binary file modified precompile/binaries/minlib/managed_coin.mv
Binary file not shown.
Binary file modified precompile/binaries/minlib/primary_fungible_store.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/account.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/coin.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/fungible_asset.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/managed_coin.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/primary_fungible_store.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/staking.mv
Binary file not shown.
Loading
Loading