From d6451335d9610f6a24a21d222d9e65b81ff1eec3 Mon Sep 17 00:00:00 2001 From: jeffyanta Date: Tue, 2 Dec 2025 14:44:26 -0500 Subject: [PATCH] Standardize on vm over cvm --- go.sum | 2 - ocp/common/account.go | 18 +-- ocp/common/account_test.go | 16 +-- ocp/data/internal.go | 106 +++++++++--------- ocp/data/nonce/nonce.go | 6 +- ocp/data/nonce/tests/tests.go | 6 +- ocp/data/timelock/timelock.go | 2 +- ocp/data/{cvm => vm}/ram/account.go | 6 +- ocp/data/{cvm => vm}/ram/memory/store.go | 18 +-- ocp/data/{cvm => vm}/ram/memory/store_test.go | 2 +- ocp/data/{cvm => vm}/ram/postgres/model.go | 8 +- ocp/data/{cvm => vm}/ram/postgres/store.go | 16 +-- .../{cvm => vm}/ram/postgres/store_test.go | 4 +- ocp/data/{cvm => vm}/ram/store.go | 4 +- ocp/data/{cvm => vm}/ram/tests/tests.go | 26 ++--- ocp/data/{cvm => vm}/ram/util.go | 4 +- ocp/data/{cvm => vm}/ram/util_test.go | 12 +- ocp/data/{cvm => vm}/storage/account.go | 0 ocp/data/{cvm => vm}/storage/memory/store.go | 10 +- .../{cvm => vm}/storage/memory/store_test.go | 2 +- .../{cvm => vm}/storage/postgres/model.go | 2 +- .../{cvm => vm}/storage/postgres/store.go | 6 +- .../storage/postgres/store_test.go | 4 +- ocp/data/{cvm => vm}/storage/store.go | 0 ocp/data/{cvm => vm}/storage/tests/tests.go | 2 +- ocp/rpc/transaction/action_handler.go | 14 +-- ocp/rpc/transaction/airdrop.go | 8 +- ocp/rpc/transaction/errors.go | 4 +- ocp/rpc/transaction/intent.go | 6 +- ocp/rpc/transaction/server.go | 2 +- ocp/rpc/transaction/swap_handler.go | 46 ++++---- ocp/transaction/nonce_pool_test.go | 2 +- ocp/transaction/transaction.go | 50 ++++----- ocp/vm/virtual_account.go | 14 +-- ocp/worker/geyser/external_deposit.go | 14 +-- ocp/worker/geyser/timelock.go | 6 +- ocp/worker/nonce/metrics.go | 4 +- ocp/worker/nonce/pool.go | 8 +- ocp/worker/nonce/runtime.go | 6 +- ocp/worker/nonce/util.go | 6 +- ocp/worker/sequencer/fulfillment_handler.go | 22 ++-- ocp/worker/sequencer/vm.go | 8 +- ocp/worker/swap/util.go | 18 +-- .../instructions_buy_and_deposit_into_vm.go | 4 +- .../instructions_sell_and_deposit_into_vm.go | 4 +- solana/{cvm => vm}/accounts_code_vm.go | 2 +- solana/{cvm => vm}/accounts_memory_account.go | 2 +- solana/{cvm => vm}/accounts_relay.go | 2 +- solana/{cvm => vm}/accounts_storage.go | 2 +- solana/{cvm => vm}/accounts_unlock_state.go | 2 +- solana/{cvm => vm}/address.go | 2 +- .../{cvm => vm}/instructions_cancel_swap.go | 2 +- ...nstructions_close_swap_account_if_empty.go | 2 +- solana/{cvm => vm}/instructions_compress.go | 2 +- solana/{cvm => vm}/instructions_decompress.go | 2 +- solana/{cvm => vm}/instructions_exec.go | 2 +- .../{cvm => vm}/instructions_init_memory.go | 2 +- solana/{cvm => vm}/instructions_init_nonce.go | 2 +- solana/{cvm => vm}/instructions_init_relay.go | 2 +- .../{cvm => vm}/instructions_init_storage.go | 2 +- .../{cvm => vm}/instructions_init_timelock.go | 2 +- .../{cvm => vm}/instructions_init_unlock.go | 2 +- solana/{cvm => vm}/instructions_init_vm.go | 2 +- .../{cvm => vm}/instructions_resize_memory.go | 2 +- solana/{cvm => vm}/instructions_snapshot.go | 2 +- .../instructions_timelock_deposit_from_pda.go | 2 +- .../instructions_transfer_for_swap.go | 2 +- solana/{cvm => vm}/program.go | 2 +- solana/{cvm => vm}/transaction.go | 2 +- solana/{cvm => vm}/types_account_type.go | 2 +- solana/{cvm => vm}/types_code_instruction.go | 2 +- solana/{cvm => vm}/types_hash.go | 2 +- solana/{cvm => vm}/types_item_state.go | 2 +- solana/{cvm => vm}/types_memory_allocator.go | 2 +- solana/{cvm => vm}/types_memory_layout.go | 2 +- solana/{cvm => vm}/types_memory_version.go | 2 +- solana/{cvm => vm}/types_merkle_tree.go | 2 +- solana/{cvm => vm}/types_message.go | 2 +- solana/{cvm => vm}/types_opcode.go | 2 +- solana/{cvm => vm}/types_recent_roots.go | 2 +- solana/{cvm => vm}/types_signature.go | 2 +- solana/{cvm => vm}/types_slice_allocator.go | 2 +- solana/{cvm => vm}/types_timelock_state.go | 2 +- solana/{cvm => vm}/types_token_pool.go | 2 +- .../{cvm => vm}/types_virtual_account_type.go | 2 +- solana/{cvm => vm}/utils.go | 2 +- solana/{cvm => vm}/virtual_accounts.go | 2 +- .../virtual_accounts_durable_nonce.go | 2 +- .../virtual_accounts_relay_account.go | 2 +- .../virtual_accounts_timelock_account.go | 2 +- solana/{cvm => vm}/virtual_instructions.go | 2 +- .../virtual_instructions_airdrop.go | 2 +- ...rtual_instructions_conditional_transfer.go | 2 +- .../virtual_instructions_external_relay.go | 2 +- .../virtual_instructions_external_transfer.go | 2 +- .../virtual_instructions_external_withdraw.go | 2 +- .../{cvm => vm}/virtual_instructions_relay.go | 2 +- .../virtual_instructions_transfer.go | 2 +- .../virtual_instructions_withdraw.go | 2 +- 99 files changed, 317 insertions(+), 319 deletions(-) rename ocp/data/{cvm => vm}/ram/account.go (87%) rename ocp/data/{cvm => vm}/ram/memory/store.go (83%) rename ocp/data/{cvm => vm}/ram/memory/store_test.go (76%) rename ocp/data/{cvm => vm}/ram/postgres/model.go (95%) rename ocp/data/{cvm => vm}/ram/postgres/store.go (65%) rename ocp/data/{cvm => vm}/ram/postgres/store_test.go (96%) rename ocp/data/{cvm => vm}/ram/store.go (88%) rename ocp/data/{cvm => vm}/ram/tests/tests.go (72%) rename ocp/data/{cvm => vm}/ram/util.go (76%) rename ocp/data/{cvm => vm}/ram/util_test.go (64%) rename ocp/data/{cvm => vm}/storage/account.go (100%) rename ocp/data/{cvm => vm}/storage/memory/store.go (89%) rename ocp/data/{cvm => vm}/storage/memory/store_test.go (75%) rename ocp/data/{cvm => vm}/storage/postgres/model.go (98%) rename ocp/data/{cvm => vm}/storage/postgres/store.go (85%) rename ocp/data/{cvm => vm}/storage/postgres/store_test.go (95%) rename ocp/data/{cvm => vm}/storage/store.go (100%) rename ocp/data/{cvm => vm}/storage/tests/tests.go (97%) rename solana/{cvm => vm}/accounts_code_vm.go (99%) rename solana/{cvm => vm}/accounts_memory_account.go (99%) rename solana/{cvm => vm}/accounts_relay.go (99%) rename solana/{cvm => vm}/accounts_storage.go (90%) rename solana/{cvm => vm}/accounts_unlock_state.go (99%) rename solana/{cvm => vm}/address.go (99%) rename solana/{cvm => vm}/instructions_cancel_swap.go (99%) rename solana/{cvm => vm}/instructions_close_swap_account_if_empty.go (99%) rename solana/{cvm => vm}/instructions_compress.go (99%) rename solana/{cvm => vm}/instructions_decompress.go (99%) rename solana/{cvm => vm}/instructions_exec.go (99%) rename solana/{cvm => vm}/instructions_init_memory.go (99%) rename solana/{cvm => vm}/instructions_init_nonce.go (99%) rename solana/{cvm => vm}/instructions_init_relay.go (99%) rename solana/{cvm => vm}/instructions_init_storage.go (99%) rename solana/{cvm => vm}/instructions_init_timelock.go (99%) rename solana/{cvm => vm}/instructions_init_unlock.go (99%) rename solana/{cvm => vm}/instructions_init_vm.go (99%) rename solana/{cvm => vm}/instructions_resize_memory.go (99%) rename solana/{cvm => vm}/instructions_snapshot.go (98%) rename solana/{cvm => vm}/instructions_timelock_deposit_from_pda.go (99%) rename solana/{cvm => vm}/instructions_transfer_for_swap.go (99%) rename solana/{cvm => vm}/program.go (98%) rename solana/{cvm => vm}/transaction.go (93%) rename solana/{cvm => vm}/types_account_type.go (94%) rename solana/{cvm => vm}/types_code_instruction.go (98%) rename solana/{cvm => vm}/types_hash.go (98%) rename solana/{cvm => vm}/types_item_state.go (98%) rename solana/{cvm => vm}/types_memory_allocator.go (92%) rename solana/{cvm => vm}/types_memory_layout.go (98%) rename solana/{cvm => vm}/types_memory_version.go (96%) rename solana/{cvm => vm}/types_merkle_tree.go (98%) rename solana/{cvm => vm}/types_message.go (99%) rename solana/{cvm => vm}/types_opcode.go (97%) rename solana/{cvm => vm}/types_recent_roots.go (98%) rename solana/{cvm => vm}/types_signature.go (97%) rename solana/{cvm => vm}/types_slice_allocator.go (99%) rename solana/{cvm => vm}/types_timelock_state.go (97%) rename solana/{cvm => vm}/types_token_pool.go (98%) rename solana/{cvm => vm}/types_virtual_account_type.go (97%) rename solana/{cvm => vm}/utils.go (99%) rename solana/{cvm => vm}/virtual_accounts.go (97%) rename solana/{cvm => vm}/virtual_accounts_durable_nonce.go (98%) rename solana/{cvm => vm}/virtual_accounts_relay_account.go (98%) rename solana/{cvm => vm}/virtual_accounts_timelock_account.go (99%) rename solana/{cvm => vm}/virtual_instructions.go (84%) rename solana/{cvm => vm}/virtual_instructions_airdrop.go (97%) rename solana/{cvm => vm}/virtual_instructions_conditional_transfer.go (97%) rename solana/{cvm => vm}/virtual_instructions_external_relay.go (98%) rename solana/{cvm => vm}/virtual_instructions_external_transfer.go (97%) rename solana/{cvm => vm}/virtual_instructions_external_withdraw.go (97%) rename solana/{cvm => vm}/virtual_instructions_relay.go (98%) rename solana/{cvm => vm}/virtual_instructions_transfer.go (97%) rename solana/{cvm => vm}/virtual_instructions_withdraw.go (97%) diff --git a/go.sum b/go.sum index 3f0895d..b01246d 100644 --- a/go.sum +++ b/go.sum @@ -78,8 +78,6 @@ github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= github.com/code-payments/code-vm-indexer v1.2.0 h1:rSHpBMiT9BKgmKcXg/VIoi/h0t7jNxGx07Qz59m+6Q0= github.com/code-payments/code-vm-indexer v1.2.0/go.mod h1:vn91YN2qNqb+gGJeZe2+l+TNxVmEEiRHXXnIn2Y40h8= -github.com/code-payments/ocp-protobuf-api v0.1.0 h1:sS2x2dwL94uZ/cGNvlStZmazY26b+dWT10bOFkk+1+c= -github.com/code-payments/ocp-protobuf-api v0.1.0/go.mod h1:tw6BooY5a8l6CtSZnKOruyKII0W04n89pcM4BizrgG8= github.com/code-payments/ocp-protobuf-api v0.2.0 h1:XLDeVdPDjy+Y0xnvcu1KHf6JelWc4IgDQ4SOCRBJvzE= github.com/code-payments/ocp-protobuf-api v0.2.0/go.mod h1:tw6BooY5a8l6CtSZnKOruyKII0W04n89pcM4BizrgG8= github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw= diff --git a/ocp/common/account.go b/ocp/common/account.go index ef2f631..81edc40 100644 --- a/ocp/common/account.go +++ b/ocp/common/account.go @@ -16,9 +16,9 @@ import ( "github.com/code-payments/ocp-server/ocp/data/currency" "github.com/code-payments/ocp-server/ocp/data/timelock" "github.com/code-payments/ocp-server/solana" - "github.com/code-payments/ocp-server/solana/cvm" timelock_token_v1 "github.com/code-payments/ocp-server/solana/timelock/v1" "github.com/code-payments/ocp-server/solana/token" + "github.com/code-payments/ocp-server/solana/vm" ) type Account struct { @@ -239,7 +239,7 @@ func (a *Account) GetTimelockAccounts(vmConfig *VmConfig) (*TimelockAccounts, er return nil, errors.Wrap(err, "error validating owner account") } - stateAddress, stateBump, err := cvm.GetVirtualTimelockAccountAddress(&cvm.GetVirtualTimelockAccountAddressArgs{ + stateAddress, stateBump, err := vm.GetVirtualTimelockAccountAddress(&vm.GetVirtualTimelockAccountAddressArgs{ Mint: vmConfig.Mint.PublicKey().ToBytes(), VmAuthority: vmConfig.Authority.PublicKey().ToBytes(), Owner: a.PublicKey().ToBytes(), @@ -249,14 +249,14 @@ func (a *Account) GetTimelockAccounts(vmConfig *VmConfig) (*TimelockAccounts, er return nil, errors.Wrap(err, "error getting timelock state address") } - vaultAddress, vaultBump, err := cvm.GetVirtualTimelockVaultAddress(&cvm.GetVirtualTimelockVaultAddressArgs{ + vaultAddress, vaultBump, err := vm.GetVirtualTimelockVaultAddress(&vm.GetVirtualTimelockVaultAddressArgs{ VirtualTimelock: stateAddress, }) if err != nil { return nil, errors.Wrap(err, "error getting vault address") } - unlockAddress, unlockBump, err := cvm.GetVmUnlockStateAccountAddress(&cvm.GetVmUnlockStateAccountAddressArgs{ + unlockAddress, unlockBump, err := vm.GetVmUnlockStateAccountAddress(&vm.GetVmUnlockStateAccountAddressArgs{ VirtualAccountOwner: a.publicKey.ToBytes(), VirtualAccount: stateAddress, Vm: vmConfig.Vm.PublicKey().ToBytes(), @@ -311,7 +311,7 @@ func (a *Account) GetTimelockAccounts(vmConfig *VmConfig) (*TimelockAccounts, er } func (a *Account) GetVmDepositAccounts(vmConfig *VmConfig) (*VmDepositAccounts, error) { - depositPdaAddress, depositPdaBump, err := cvm.GetVmDepositAddress(&cvm.GetVmDepositAddressArgs{ + depositPdaAddress, depositPdaBump, err := vm.GetVmDepositAddress(&vm.GetVmDepositAddressArgs{ Depositor: a.PublicKey().ToBytes(), Vm: vmConfig.Vm.PublicKey().ToBytes(), }) @@ -348,7 +348,7 @@ func (a *Account) GetVmDepositAccounts(vmConfig *VmConfig) (*VmDepositAccounts, } func (a *Account) GetVmSwapAccounts(vmConfig *VmConfig) (*VmSwapAccounts, error) { - swapPdaAddress, swapPdaBump, err := cvm.GetVmSwapAddress(&cvm.GetVmSwapAddressArgs{ + swapPdaAddress, swapPdaBump, err := vm.GetVmSwapAddress(&vm.GetVmSwapAddressArgs{ Swapper: a.PublicKey().ToBytes(), Vm: vmConfig.Vm.PublicKey().ToBytes(), }) @@ -488,14 +488,14 @@ func (a *TimelockAccounts) GetDBRecord(ctx context.Context, data ocp_data.Provid // GetInitializeInstruction gets a SystemTimelockInitInstruction instruction for a Timelock account func (a *TimelockAccounts) GetInitializeInstruction(vmAuthority, memory *Account, accountIndex uint16) (solana.Instruction, error) { - return cvm.NewInitTimelockInstruction( - &cvm.InitTimelockInstructionAccounts{ + return vm.NewInitTimelockInstruction( + &vm.InitTimelockInstructionAccounts{ VmAuthority: vmAuthority.PublicKey().ToBytes(), Vm: a.Vm.PublicKey().ToBytes(), VmMemory: memory.PublicKey().ToBytes(), VirtualAccountOwner: a.VaultOwner.PublicKey().ToBytes(), }, - &cvm.InitTimelockInstructionArgs{ + &vm.InitTimelockInstructionArgs{ AccountIndex: accountIndex, VirtualTimelockBump: a.StateBump, VirtualVaultBump: a.VaultBump, diff --git a/ocp/common/account_test.go b/ocp/common/account_test.go index 636a945..3d27fd2 100644 --- a/ocp/common/account_test.go +++ b/ocp/common/account_test.go @@ -12,9 +12,9 @@ import ( commonpb "github.com/code-payments/ocp-protobuf-api/generated/go/common/v1" ocp_data "github.com/code-payments/ocp-server/ocp/data" - "github.com/code-payments/ocp-server/solana/cvm" timelock_token_v1 "github.com/code-payments/ocp-server/solana/timelock/v1" "github.com/code-payments/ocp-server/solana/token" + "github.com/code-payments/ocp-server/solana/vm" ) func TestAccountWithPublicKey(t *testing.T) { @@ -107,7 +107,7 @@ func TestConvertToTimelockVault(t *testing.T) { ownerAccount := newRandomTestAccount(t) - stateAddress, _, err := cvm.GetVirtualTimelockAccountAddress(&cvm.GetVirtualTimelockAccountAddressArgs{ + stateAddress, _, err := vm.GetVirtualTimelockAccountAddress(&vm.GetVirtualTimelockAccountAddressArgs{ Mint: vmConfig.Mint.PublicKey().ToBytes(), VmAuthority: vmConfig.Authority.PublicKey().ToBytes(), Owner: ownerAccount.PublicKey().ToBytes(), @@ -115,7 +115,7 @@ func TestConvertToTimelockVault(t *testing.T) { }) require.NoError(t, err) - expectedVaultAddress, _, err := cvm.GetVirtualTimelockVaultAddress(&cvm.GetVirtualTimelockVaultAddressArgs{ + expectedVaultAddress, _, err := vm.GetVirtualTimelockVaultAddress(&vm.GetVirtualTimelockVaultAddressArgs{ VirtualTimelock: stateAddress, }) require.NoError(t, err) @@ -130,7 +130,7 @@ func TestGetTimelockAccounts(t *testing.T) { ownerAccount := newRandomTestAccount(t) - expectedStateAddress, expectedStateBump, err := cvm.GetVirtualTimelockAccountAddress(&cvm.GetVirtualTimelockAccountAddressArgs{ + expectedStateAddress, expectedStateBump, err := vm.GetVirtualTimelockAccountAddress(&vm.GetVirtualTimelockAccountAddressArgs{ Mint: vmConfig.Mint.PublicKey().ToBytes(), VmAuthority: vmConfig.Authority.PublicKey().ToBytes(), Owner: ownerAccount.PublicKey().ToBytes(), @@ -138,12 +138,12 @@ func TestGetTimelockAccounts(t *testing.T) { }) require.NoError(t, err) - expectedVaultAddress, expectedVaultBump, err := cvm.GetVirtualTimelockVaultAddress(&cvm.GetVirtualTimelockVaultAddressArgs{ + expectedVaultAddress, expectedVaultBump, err := vm.GetVirtualTimelockVaultAddress(&vm.GetVirtualTimelockVaultAddressArgs{ VirtualTimelock: expectedStateAddress, }) require.NoError(t, err) - expectedUnlockAddress, expectedUnlockBump, err := cvm.GetVmUnlockStateAccountAddress(&cvm.GetVmUnlockStateAccountAddressArgs{ + expectedUnlockAddress, expectedUnlockBump, err := vm.GetVmUnlockStateAccountAddress(&vm.GetVmUnlockStateAccountAddressArgs{ VirtualAccountOwner: ownerAccount.PublicKey().ToBytes(), VirtualAccount: expectedStateAddress, Vm: vmConfig.Vm.PublicKey().ToBytes(), @@ -168,7 +168,7 @@ func TestGetVmDepositAccounts(t *testing.T) { ownerAccount := newRandomTestAccount(t) - expectedDepositPdaAddress, expectedDepositPdaBump, err := cvm.GetVmDepositAddress(&cvm.GetVmDepositAddressArgs{ + expectedDepositPdaAddress, expectedDepositPdaBump, err := vm.GetVmDepositAddress(&vm.GetVmDepositAddressArgs{ Depositor: ownerAccount.PublicKey().ToBytes(), Vm: vmConfig.Vm.PublicKey().ToBytes(), }) @@ -192,7 +192,7 @@ func TestGetVmSwapAccounts(t *testing.T) { ownerAccount := newRandomTestAccount(t) - expectedSwapPdaAddress, expectedSwapPdaBump, err := cvm.GetVmSwapAddress(&cvm.GetVmSwapAddressArgs{ + expectedSwapPdaAddress, expectedSwapPdaBump, err := vm.GetVmSwapAddress(&vm.GetVmSwapAddressArgs{ Swapper: ownerAccount.PublicKey().ToBytes(), Vm: vmConfig.Vm.PublicKey().ToBytes(), }) diff --git a/ocp/data/internal.go b/ocp/data/internal.go index fd556bb..a93085a 100644 --- a/ocp/data/internal.go +++ b/ocp/data/internal.go @@ -14,8 +14,8 @@ import ( currency_lib "github.com/code-payments/ocp-server/currency" pg "github.com/code-payments/ocp-server/database/postgres" "github.com/code-payments/ocp-server/database/query" - "github.com/code-payments/ocp-server/solana/cvm" timelock_token "github.com/code-payments/ocp-server/solana/timelock/v1" + "github.com/code-payments/ocp-server/solana/vm" commonpb "github.com/code-payments/ocp-protobuf-api/generated/go/common/v1" transactionpb "github.com/code-payments/ocp-protobuf-api/generated/go/transaction/v1" @@ -24,8 +24,6 @@ import ( "github.com/code-payments/ocp-server/ocp/data/action" "github.com/code-payments/ocp-server/ocp/data/balance" "github.com/code-payments/ocp-server/ocp/data/currency" - cvm_ram "github.com/code-payments/ocp-server/ocp/data/cvm/ram" - cvm_storage "github.com/code-payments/ocp-server/ocp/data/cvm/storage" "github.com/code-payments/ocp-server/ocp/data/deposit" "github.com/code-payments/ocp-server/ocp/data/fulfillment" "github.com/code-payments/ocp-server/ocp/data/intent" @@ -36,13 +34,13 @@ import ( "github.com/code-payments/ocp-server/ocp/data/timelock" "github.com/code-payments/ocp-server/ocp/data/transaction" "github.com/code-payments/ocp-server/ocp/data/vault" + vm_ram "github.com/code-payments/ocp-server/ocp/data/vm/ram" + vm_storage "github.com/code-payments/ocp-server/ocp/data/vm/storage" account_memory_client "github.com/code-payments/ocp-server/ocp/data/account/memory" action_memory_client "github.com/code-payments/ocp-server/ocp/data/action/memory" balance_memory_client "github.com/code-payments/ocp-server/ocp/data/balance/memory" currency_memory_client "github.com/code-payments/ocp-server/ocp/data/currency/memory" - cvm_ram_memory_client "github.com/code-payments/ocp-server/ocp/data/cvm/ram/memory" - cvm_storage_memory_client "github.com/code-payments/ocp-server/ocp/data/cvm/storage/memory" deposit_memory_client "github.com/code-payments/ocp-server/ocp/data/deposit/memory" fulfillment_memory_client "github.com/code-payments/ocp-server/ocp/data/fulfillment/memory" intent_memory_client "github.com/code-payments/ocp-server/ocp/data/intent/memory" @@ -53,13 +51,13 @@ import ( timelock_memory_client "github.com/code-payments/ocp-server/ocp/data/timelock/memory" transaction_memory_client "github.com/code-payments/ocp-server/ocp/data/transaction/memory" vault_memory_client "github.com/code-payments/ocp-server/ocp/data/vault/memory" + vm_ram_memory_client "github.com/code-payments/ocp-server/ocp/data/vm/ram/memory" + vm_storage_memory_client "github.com/code-payments/ocp-server/ocp/data/vm/storage/memory" account_postgres_client "github.com/code-payments/ocp-server/ocp/data/account/postgres" action_postgres_client "github.com/code-payments/ocp-server/ocp/data/action/postgres" balance_postgres_client "github.com/code-payments/ocp-server/ocp/data/balance/postgres" currency_postgres_client "github.com/code-payments/ocp-server/ocp/data/currency/postgres" - cvm_ram_postgres_client "github.com/code-payments/ocp-server/ocp/data/cvm/ram/postgres" - cvm_storage_postgres_client "github.com/code-payments/ocp-server/ocp/data/cvm/storage/postgres" deposit_postgres_client "github.com/code-payments/ocp-server/ocp/data/deposit/postgres" fulfillment_postgres_client "github.com/code-payments/ocp-server/ocp/data/fulfillment/postgres" intent_postgres_client "github.com/code-payments/ocp-server/ocp/data/intent/postgres" @@ -70,6 +68,8 @@ import ( timelock_postgres_client "github.com/code-payments/ocp-server/ocp/data/timelock/postgres" transaction_postgres_client "github.com/code-payments/ocp-server/ocp/data/transaction/postgres" vault_postgres_client "github.com/code-payments/ocp-server/ocp/data/vault/postgres" + vm_ram_postgres_client "github.com/code-payments/ocp-server/ocp/data/vm/ram/postgres" + vm_storage_postgres_client "github.com/code-payments/ocp-server/ocp/data/vm/storage/postgres" ) // Cache Constants @@ -137,19 +137,6 @@ type DatabaseData interface { PutCurrencyReserve(ctx context.Context, record *currency.ReserveRecord) error GetCurrencyReserveAtTime(ctx context.Context, mint string, t time.Time) (*currency.ReserveRecord, error) - // CVM RAM - // -------------------------------------------------------------------------------- - InitializeVmMemory(ctx context.Context, record *cvm_ram.Record) error - FreeVmMemoryByIndex(ctx context.Context, memoryAccount string, index uint16) error - FreeVmMemoryByAddress(ctx context.Context, address string) error - ReserveVmMemory(ctx context.Context, vm string, accountType cvm.VirtualAccountType, address string) (string, uint16, error) - - // CVM Storage - // -------------------------------------------------------------------------------- - InitializeVmStorage(ctx context.Context, record *cvm_storage.Record) error - FindAnyVmStorageWithAvailableCapacity(ctx context.Context, vm string, purpose cvm_storage.Purpose, minCapacity uint64) (*cvm_storage.Record, error) - ReserveVmStorage(ctx context.Context, vm string, purpose cvm_storage.Purpose, address string) (string, error) - // Deposits // -------------------------------------------------------------------------------- SaveExternalDeposit(ctx context.Context, record *deposit.Record) error @@ -251,6 +238,19 @@ type DatabaseData interface { GetAllKeysByState(ctx context.Context, state vault.State, opts ...query.Option) ([]*vault.Record, error) SaveKey(ctx context.Context, record *vault.Record) error + // VM RAM + // -------------------------------------------------------------------------------- + InitializeVmMemory(ctx context.Context, record *vm_ram.Record) error + FreeVmMemoryByIndex(ctx context.Context, memoryAccount string, index uint16) error + FreeVmMemoryByAddress(ctx context.Context, address string) error + ReserveVmMemory(ctx context.Context, vm string, accountType vm.VirtualAccountType, address string) (string, uint16, error) + + // VM Storage + // -------------------------------------------------------------------------------- + InitializeVmStorage(ctx context.Context, record *vm_storage.Record) error + FindAnyVmStorageWithAvailableCapacity(ctx context.Context, vm string, purpose vm_storage.Purpose, minCapacity uint64) (*vm_storage.Record, error) + ReserveVmStorage(ctx context.Context, vm string, purpose vm_storage.Purpose, address string) (string, error) + // ExecuteInTx executes fn with a single DB transaction that is scoped to the call. // This enables more complex transactions that can span many calls across the provider. // @@ -265,8 +265,6 @@ type DatabaseProvider struct { actions action.Store balance balance.Store currencies currency.Store - cvmRam cvm_ram.Store - cvmStorage cvm_storage.Store deposits deposit.Store fulfillments fulfillment.Store intents intent.Store @@ -277,6 +275,8 @@ type DatabaseProvider struct { timelocks timelock.Store transactions transaction.Store vault vault.Store + vmRam vm_ram.Store + vmStorage vm_storage.Store exchangeCache cache.Cache timelockCache cache.Cache @@ -310,8 +310,6 @@ func NewDatabaseProvider(dbConfig *pg.Config) (DatabaseData, error) { actions: action_postgres_client.New(db), balance: balance_postgres_client.New(db), currencies: currency_postgres_client.New(db), - cvmRam: cvm_ram_postgres_client.New(db), - cvmStorage: cvm_storage_postgres_client.New(db), deposits: deposit_postgres_client.New(db), fulfillments: fulfillment_postgres_client.New(db), intents: intent_postgres_client.New(db), @@ -322,6 +320,8 @@ func NewDatabaseProvider(dbConfig *pg.Config) (DatabaseData, error) { timelocks: timelock_postgres_client.New(db), transactions: transaction_postgres_client.New(db), vault: vault_postgres_client.New(db), + vmRam: vm_ram_postgres_client.New(db), + vmStorage: vm_storage_postgres_client.New(db), exchangeCache: cache.NewCache(maxExchangeRateCacheBudget), timelockCache: cache.NewCache(maxTimelockCacheBudget), @@ -336,8 +336,6 @@ func NewTestDatabaseProvider() DatabaseData { actions: action_memory_client.New(), balance: balance_memory_client.New(), currencies: currency_memory_client.New(), - cvmRam: cvm_ram_memory_client.New(), - cvmStorage: cvm_storage_memory_client.New(), deposits: deposit_memory_client.New(), fulfillments: fulfillment_memory_client.New(), intents: intent_memory_client.New(), @@ -348,6 +346,8 @@ func NewTestDatabaseProvider() DatabaseData { timelocks: timelock_memory_client.New(), transactions: transaction_memory_client.New(), vault: vault_memory_client.New(), + vmRam: vm_ram_memory_client.New(), + vmStorage: vm_storage_memory_client.New(), exchangeCache: cache.NewCache(maxExchangeRateCacheBudget), timelockCache: nil, // Shouldn't be used for tests @@ -524,33 +524,6 @@ func (dp *DatabaseProvider) GetCurrencyReserveAtTime(ctx context.Context, mint s return dp.currencies.GetReserveAtTime(ctx, mint, t) } -// CVM RAM -// -------------------------------------------------------------------------------- -func (dp *DatabaseProvider) InitializeVmMemory(ctx context.Context, record *cvm_ram.Record) error { - return dp.cvmRam.InitializeMemory(ctx, record) -} -func (dp *DatabaseProvider) FreeVmMemoryByIndex(ctx context.Context, memoryAccount string, index uint16) error { - return dp.cvmRam.FreeMemoryByIndex(ctx, memoryAccount, index) -} -func (dp *DatabaseProvider) FreeVmMemoryByAddress(ctx context.Context, address string) error { - return dp.cvmRam.FreeMemoryByAddress(ctx, address) -} -func (dp *DatabaseProvider) ReserveVmMemory(ctx context.Context, vm string, accountType cvm.VirtualAccountType, address string) (string, uint16, error) { - return dp.cvmRam.ReserveMemory(ctx, vm, accountType, address) -} - -// CVM Storage -// -------------------------------------------------------------------------------- -func (dp *DatabaseProvider) InitializeVmStorage(ctx context.Context, record *cvm_storage.Record) error { - return dp.cvmStorage.InitializeStorage(ctx, record) -} -func (dp *DatabaseProvider) FindAnyVmStorageWithAvailableCapacity(ctx context.Context, vm string, purpose cvm_storage.Purpose, minCapacity uint64) (*cvm_storage.Record, error) { - return dp.cvmStorage.FindAnyWithAvailableCapacity(ctx, vm, purpose, minCapacity) -} -func (dp *DatabaseProvider) ReserveVmStorage(ctx context.Context, vm string, purpose cvm_storage.Purpose, address string) (string, error) { - return dp.cvmStorage.ReserveStorage(ctx, vm, purpose, address) -} - // Deposits // -------------------------------------------------------------------------------- func (dp *DatabaseProvider) SaveExternalDeposit(ctx context.Context, record *deposit.Record) error { @@ -908,3 +881,30 @@ func (dp *DatabaseProvider) GetAllKeysByState(ctx context.Context, state vault.S func (dp *DatabaseProvider) SaveKey(ctx context.Context, record *vault.Record) error { return dp.vault.Save(ctx, record) } + +// VM RAM +// -------------------------------------------------------------------------------- +func (dp *DatabaseProvider) InitializeVmMemory(ctx context.Context, record *vm_ram.Record) error { + return dp.vmRam.InitializeMemory(ctx, record) +} +func (dp *DatabaseProvider) FreeVmMemoryByIndex(ctx context.Context, memoryAccount string, index uint16) error { + return dp.vmRam.FreeMemoryByIndex(ctx, memoryAccount, index) +} +func (dp *DatabaseProvider) FreeVmMemoryByAddress(ctx context.Context, address string) error { + return dp.vmRam.FreeMemoryByAddress(ctx, address) +} +func (dp *DatabaseProvider) ReserveVmMemory(ctx context.Context, vm string, accountType vm.VirtualAccountType, address string) (string, uint16, error) { + return dp.vmRam.ReserveMemory(ctx, vm, accountType, address) +} + +// VM Storage +// -------------------------------------------------------------------------------- +func (dp *DatabaseProvider) InitializeVmStorage(ctx context.Context, record *vm_storage.Record) error { + return dp.vmStorage.InitializeStorage(ctx, record) +} +func (dp *DatabaseProvider) FindAnyVmStorageWithAvailableCapacity(ctx context.Context, vm string, purpose vm_storage.Purpose, minCapacity uint64) (*vm_storage.Record, error) { + return dp.vmStorage.FindAnyWithAvailableCapacity(ctx, vm, purpose, minCapacity) +} +func (dp *DatabaseProvider) ReserveVmStorage(ctx context.Context, vm string, purpose vm_storage.Purpose, address string) (string, error) { + return dp.vmStorage.ReserveStorage(ctx, vm, purpose, address) +} diff --git a/ocp/data/nonce/nonce.go b/ocp/data/nonce/nonce.go index 80a7214..c94544f 100644 --- a/ocp/data/nonce/nonce.go +++ b/ocp/data/nonce/nonce.go @@ -14,7 +14,7 @@ type Environment uint8 const ( EnvironmentUnknown Environment = iota EnvironmentSolana // Environment instance is the cluster name (ie. mainnet, devnet, testnet, etc) - EnvironmentCvm // Environment instance is the VM public key + EnvironmentVm // Environment instance is the VM public key ) const ( @@ -174,8 +174,8 @@ func (e Environment) String() string { return "unknown" case EnvironmentSolana: return "solana" - case EnvironmentCvm: - return "cvm" + case EnvironmentVm: + return "vm" } return "unknown" } diff --git a/ocp/data/nonce/tests/tests.go b/ocp/data/nonce/tests/tests.go index 11a0398..9b79fe1 100644 --- a/ocp/data/nonce/tests/tests.go +++ b/ocp/data/nonce/tests/tests.go @@ -12,8 +12,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/code-payments/ocp-server/ocp/data/nonce" "github.com/code-payments/ocp-server/database/query" + "github.com/code-payments/ocp-server/ocp/data/nonce" "github.com/code-payments/ocp-server/pointer" ) @@ -391,10 +391,10 @@ func testBatchClaimAvailableByPurpose(t *testing.T, s nonce.Store) { require.NoError(t, s.Save(ctx, record)) record = &nonce.Record{ - Address: fmt.Sprintf("nonce_cvm_%d", i), + Address: fmt.Sprintf("nonce_vm_%d", i), Authority: "authority", Blockhash: "bh", - Environment: nonce.EnvironmentCvm, + Environment: nonce.EnvironmentVm, EnvironmentInstance: "pubkey", Purpose: nonce.PurposeClientIntent, State: nonce.StateClaimed, diff --git a/ocp/data/timelock/timelock.go b/ocp/data/timelock/timelock.go index d097842..05358ef 100644 --- a/ocp/data/timelock/timelock.go +++ b/ocp/data/timelock/timelock.go @@ -23,7 +23,7 @@ type Record struct { VaultAddress string VaultBump uint8 VaultOwner string - VaultState timelock_token_v1.TimelockState // Uses the original Timelock account state since the CVM only defines enum states for unlock + VaultState timelock_token_v1.TimelockState // Uses the original Timelock account state since the VM only defines enum states for unlock DepositPdaAddress string DepositPdaBump uint8 diff --git a/ocp/data/cvm/ram/account.go b/ocp/data/vm/ram/account.go similarity index 87% rename from ocp/data/cvm/ram/account.go rename to ocp/data/vm/ram/account.go index 8a04e77..0e82699 100644 --- a/ocp/data/cvm/ram/account.go +++ b/ocp/data/vm/ram/account.go @@ -4,7 +4,7 @@ import ( "errors" "time" - "github.com/code-payments/ocp-server/solana/cvm" + "github.com/code-payments/ocp-server/solana/vm" ) type Record struct { @@ -19,7 +19,7 @@ type Record struct { NumPages uint16 PageSize uint8 - StoredAccountType cvm.VirtualAccountType + StoredAccountType vm.VirtualAccountType CreatedAt time.Time } @@ -46,7 +46,7 @@ func (r *Record) Validate() error { } switch r.StoredAccountType { - case cvm.VirtualAccountTypeDurableNonce, cvm.VirtualAccountTypeRelay, cvm.VirtualAccountTypeTimelock: + case vm.VirtualAccountTypeDurableNonce, vm.VirtualAccountTypeTimelock: default: return errors.New("invalid stored account type") } diff --git a/ocp/data/cvm/ram/memory/store.go b/ocp/data/vm/ram/memory/store.go similarity index 83% rename from ocp/data/cvm/ram/memory/store.go rename to ocp/data/vm/ram/memory/store.go index 59964be..f41f523 100644 --- a/ocp/data/cvm/ram/memory/store.go +++ b/ocp/data/vm/ram/memory/store.go @@ -6,8 +6,8 @@ import ( "sync" "time" - "github.com/code-payments/ocp-server/ocp/data/cvm/ram" - "github.com/code-payments/ocp-server/solana/cvm" + "github.com/code-payments/ocp-server/ocp/data/vm/ram" + "github.com/code-payments/ocp-server/solana/vm" ) type store struct { @@ -18,7 +18,7 @@ type store struct { storedVirtualAccounts map[string]string } -// New returns a new in memory cvm.ram.Store +// New returns a new in memory vm.ram.Store func New() ram.Store { return &store{ reservedAccountIndices: make(map[string]string), @@ -26,7 +26,7 @@ func New() ram.Store { } } -// InitializeMemory implements cvm.ram.Store.InitializeMemory +// InitializeMemory implements vm.ram.Store.InitializeMemory func (s *store) InitializeMemory(_ context.Context, record *ram.Record) error { if err := record.Validate(); err != nil { return err @@ -51,7 +51,7 @@ func (s *store) InitializeMemory(_ context.Context, record *ram.Record) error { return nil } -// FreeMemoryByIndex implements cvm.ram.Store.FreeMemoryByIndex +// FreeMemoryByIndex implements vm.ram.Store.FreeMemoryByIndex func (s *store) FreeMemoryByIndex(_ context.Context, memoryAccount string, index uint16) error { s.mu.Lock() defer s.mu.Unlock() @@ -68,7 +68,7 @@ func (s *store) FreeMemoryByIndex(_ context.Context, memoryAccount string, index return nil } -// FreeMemoryByAddress implements cvm.ram.Store.FreeMemoryByAddress +// FreeMemoryByAddress implements vm.ram.Store.FreeMemoryByAddress func (s *store) FreeMemoryByAddress(_ context.Context, address string) error { s.mu.Lock() defer s.mu.Unlock() @@ -84,8 +84,8 @@ func (s *store) FreeMemoryByAddress(_ context.Context, address string) error { return nil } -// ReserveMemory implements cvm.ram.Store.ReserveMemory -func (s *store) ReserveMemory(_ context.Context, vm string, accountType cvm.VirtualAccountType, address string) (string, uint16, error) { +// ReserveMemory implements vm.ram.Store.ReserveMemory +func (s *store) ReserveMemory(_ context.Context, vm string, accountType vm.VirtualAccountType, address string) (string, uint16, error) { s.mu.Lock() defer s.mu.Unlock() @@ -126,7 +126,7 @@ func (s *store) find(data *ram.Record) *ram.Record { return nil } -func (s *store) findByVmAndAccountType(vm string, accountType cvm.VirtualAccountType) []*ram.Record { +func (s *store) findByVmAndAccountType(vm string, accountType vm.VirtualAccountType) []*ram.Record { var res []*ram.Record for _, item := range s.records { if item.Vm != vm { diff --git a/ocp/data/cvm/ram/memory/store_test.go b/ocp/data/vm/ram/memory/store_test.go similarity index 76% rename from ocp/data/cvm/ram/memory/store_test.go rename to ocp/data/vm/ram/memory/store_test.go index 665e9db..ec2a67e 100644 --- a/ocp/data/cvm/ram/memory/store_test.go +++ b/ocp/data/vm/ram/memory/store_test.go @@ -3,7 +3,7 @@ package memory import ( "testing" - "github.com/code-payments/ocp-server/ocp/data/cvm/ram/tests" + "github.com/code-payments/ocp-server/ocp/data/vm/ram/tests" ) func TestVmRamMemoryStore(t *testing.T) { diff --git a/ocp/data/cvm/ram/postgres/model.go b/ocp/data/vm/ram/postgres/model.go similarity index 95% rename from ocp/data/cvm/ram/postgres/model.go rename to ocp/data/vm/ram/postgres/model.go index 6b6a713..e1f56d1 100644 --- a/ocp/data/cvm/ram/postgres/model.go +++ b/ocp/data/vm/ram/postgres/model.go @@ -7,9 +7,9 @@ import ( "github.com/jmoiron/sqlx" - "github.com/code-payments/ocp-server/ocp/data/cvm/ram" pgutil "github.com/code-payments/ocp-server/database/postgres" - "github.com/code-payments/ocp-server/solana/cvm" + "github.com/code-payments/ocp-server/ocp/data/vm/ram" + "github.com/code-payments/ocp-server/solana/vm" ) const ( @@ -82,7 +82,7 @@ func fromAccountModel(obj *accountModel) *ram.Record { NumPages: obj.NumPages, PageSize: obj.PageSize, - StoredAccountType: cvm.VirtualAccountType(obj.StoredAccountType), + StoredAccountType: vm.VirtualAccountType(obj.StoredAccountType), CreatedAt: obj.CreatedAt, } @@ -176,7 +176,7 @@ func dbFreeMemoryByAddress(ctx context.Context, db *sqlx.DB, address string) err }) } -func dbReserveMemory(ctx context.Context, db *sqlx.DB, vm string, accountType cvm.VirtualAccountType, address string) (string, uint16, error) { +func dbReserveMemory(ctx context.Context, db *sqlx.DB, vm string, accountType vm.VirtualAccountType, address string) (string, uint16, error) { var memoryAccount string var index uint16 err := pgutil.ExecuteInTx(ctx, db, sql.LevelDefault, func(tx *sqlx.Tx) error { diff --git a/ocp/data/cvm/ram/postgres/store.go b/ocp/data/vm/ram/postgres/store.go similarity index 65% rename from ocp/data/cvm/ram/postgres/store.go rename to ocp/data/vm/ram/postgres/store.go index 707c1c8..c6d3c3d 100644 --- a/ocp/data/cvm/ram/postgres/store.go +++ b/ocp/data/vm/ram/postgres/store.go @@ -6,22 +6,22 @@ import ( "github.com/jmoiron/sqlx" - "github.com/code-payments/ocp-server/ocp/data/cvm/ram" - "github.com/code-payments/ocp-server/solana/cvm" + "github.com/code-payments/ocp-server/ocp/data/vm/ram" + "github.com/code-payments/ocp-server/solana/vm" ) type store struct { db *sqlx.DB } -// New returns a new postgres cvm.ram.Store +// New returns a new postgres vm.ram.Store func New(db *sql.DB) ram.Store { return &store{ db: sqlx.NewDb(db, "pgx"), } } -// InitializeMemory implements cvm.ram.Store.InitializeMemory +// InitializeMemory implements vm.ram.Store.InitializeMemory func (s *store) InitializeMemory(ctx context.Context, record *ram.Record) error { model, err := toAccountModel(record) if err != nil { @@ -39,17 +39,17 @@ func (s *store) InitializeMemory(ctx context.Context, record *ram.Record) error return nil } -// FreeMemoryByIndex implements cvm.ram.Store.FreeMemoryByIndex +// FreeMemoryByIndex implements vm.ram.Store.FreeMemoryByIndex func (s *store) FreeMemoryByIndex(ctx context.Context, memoryAccount string, index uint16) error { return dbFreeMemoryByIndex(ctx, s.db, memoryAccount, index) } -// FreeMemoryByAddress implements cvm.ram.Store.FreeMemoryByAddress +// FreeMemoryByAddress implements vm.ram.Store.FreeMemoryByAddress func (s *store) FreeMemoryByAddress(ctx context.Context, address string) error { return dbFreeMemoryByAddress(ctx, s.db, address) } -// ReserveMemory implements cvm.ram.Store.ReserveMemory -func (s *store) ReserveMemory(ctx context.Context, vm string, accountType cvm.VirtualAccountType, address string) (string, uint16, error) { +// ReserveMemory implements vm.ram.Store.ReserveMemory +func (s *store) ReserveMemory(ctx context.Context, vm string, accountType vm.VirtualAccountType, address string) (string, uint16, error) { return dbReserveMemory(ctx, s.db, vm, accountType, address) } diff --git a/ocp/data/cvm/ram/postgres/store_test.go b/ocp/data/vm/ram/postgres/store_test.go similarity index 96% rename from ocp/data/cvm/ram/postgres/store_test.go rename to ocp/data/vm/ram/postgres/store_test.go index 91b67ce..fae5ca5 100644 --- a/ocp/data/cvm/ram/postgres/store_test.go +++ b/ocp/data/vm/ram/postgres/store_test.go @@ -8,8 +8,8 @@ import ( "github.com/ory/dockertest/v3" "go.uber.org/zap" - "github.com/code-payments/ocp-server/ocp/data/cvm/ram" - "github.com/code-payments/ocp-server/ocp/data/cvm/ram/tests" + "github.com/code-payments/ocp-server/ocp/data/vm/ram" + "github.com/code-payments/ocp-server/ocp/data/vm/ram/tests" postgrestest "github.com/code-payments/ocp-server/database/postgres/test" diff --git a/ocp/data/cvm/ram/store.go b/ocp/data/vm/ram/store.go similarity index 88% rename from ocp/data/cvm/ram/store.go rename to ocp/data/vm/ram/store.go index 1c8a834..93daf9a 100644 --- a/ocp/data/cvm/ram/store.go +++ b/ocp/data/vm/ram/store.go @@ -4,7 +4,7 @@ import ( "context" "errors" - "github.com/code-payments/ocp-server/solana/cvm" + "github.com/code-payments/ocp-server/solana/vm" ) var ( @@ -31,5 +31,5 @@ type Store interface { FreeMemoryByAddress(ctx context.Context, address string) error // ReserveMemory reserves a piece of memory in a VM for the virtual account address - ReserveMemory(ctx context.Context, vm string, accountType cvm.VirtualAccountType, address string) (string, uint16, error) + ReserveMemory(ctx context.Context, vm string, accountType vm.VirtualAccountType, address string) (string, uint16, error) } diff --git a/ocp/data/cvm/ram/tests/tests.go b/ocp/data/vm/ram/tests/tests.go similarity index 72% rename from ocp/data/cvm/ram/tests/tests.go rename to ocp/data/vm/ram/tests/tests.go index 5906bab..5611096 100644 --- a/ocp/data/cvm/ram/tests/tests.go +++ b/ocp/data/vm/ram/tests/tests.go @@ -8,8 +8,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/code-payments/ocp-server/ocp/data/cvm/ram" - "github.com/code-payments/ocp-server/solana/cvm" + "github.com/code-payments/ocp-server/ocp/data/vm/ram" + "github.com/code-payments/ocp-server/solana/vm" ) func RunTests(t *testing.T, s ram.Store, teardown func()) { @@ -31,8 +31,8 @@ func testHappyPath(t *testing.T, s ram.Store) { Capacity: 1000, NumSectors: 2, NumPages: 50, - PageSize: uint8(cvm.GetVirtualAccountSizeInMemory(cvm.VirtualAccountTypeTimelock)), - StoredAccountType: cvm.VirtualAccountTypeTimelock, + PageSize: uint8(vm.GetVirtualAccountSizeInMemory(vm.VirtualAccountTypeTimelock)), + StoredAccountType: vm.VirtualAccountTypeTimelock, } record2 := &ram.Record{ @@ -41,8 +41,8 @@ func testHappyPath(t *testing.T, s ram.Store) { Capacity: 1000, NumSectors: 2, NumPages: 50, - PageSize: uint8(cvm.GetVirtualAccountSizeInMemory(cvm.VirtualAccountTypeTimelock)) / 3, - StoredAccountType: cvm.VirtualAccountTypeTimelock, + PageSize: uint8(vm.GetVirtualAccountSizeInMemory(vm.VirtualAccountTypeTimelock)) / 3, + StoredAccountType: vm.VirtualAccountTypeTimelock, } require.NoError(t, s.InitializeMemory(ctx, record1)) @@ -50,16 +50,16 @@ func testHappyPath(t *testing.T, s ram.Store) { assert.Equal(t, ram.ErrAlreadyInitialized, s.InitializeMemory(ctx, record1)) - _, _, err := s.ReserveMemory(ctx, "vm1", cvm.VirtualAccountTypeDurableNonce, "virtualaccount") + _, _, err := s.ReserveMemory(ctx, "vm1", vm.VirtualAccountTypeDurableNonce, "virtualaccount") assert.Equal(t, ram.ErrNoFreeMemory, err) - _, _, err = s.ReserveMemory(ctx, "vm2", cvm.VirtualAccountTypeTimelock, "virtualaccount") + _, _, err = s.ReserveMemory(ctx, "vm2", vm.VirtualAccountTypeTimelock, "virtualaccount") assert.Equal(t, ram.ErrNoFreeMemory, err) address1Indices := make(map[uint16]struct{}) address2Indices := make(map[uint16]struct{}) for i := 0; i < 300; i++ { - memoryAccount, index, err := s.ReserveMemory(ctx, "vm1", cvm.VirtualAccountTypeTimelock, fmt.Sprintf("virtualaccount%d", i)) + memoryAccount, index, err := s.ReserveMemory(ctx, "vm1", vm.VirtualAccountTypeTimelock, fmt.Sprintf("virtualaccount%d", i)) if i < 100 { require.NoError(t, err) @@ -90,22 +90,22 @@ func testHappyPath(t *testing.T, s ram.Store) { } } - memoryAccount, freedIndex1, err := s.ReserveMemory(ctx, "vm1", cvm.VirtualAccountTypeTimelock, "newvirtualaccount1") + memoryAccount, freedIndex1, err := s.ReserveMemory(ctx, "vm1", vm.VirtualAccountTypeTimelock, "newvirtualaccount1") require.NoError(t, err) assert.Equal(t, "memoryaccount1", memoryAccount) assert.True(t, freedIndex1 == 42 || freedIndex1 == 66) - _, _, err = s.ReserveMemory(ctx, "vm1", cvm.VirtualAccountTypeTimelock, "newvirtualaccount1") + _, _, err = s.ReserveMemory(ctx, "vm1", vm.VirtualAccountTypeTimelock, "newvirtualaccount1") assert.Equal(t, ram.ErrAddressAlreadyReserved, err) - memoryAccount, freedIndex2, err := s.ReserveMemory(ctx, "vm1", cvm.VirtualAccountTypeTimelock, "newvirtualaccount2") + memoryAccount, freedIndex2, err := s.ReserveMemory(ctx, "vm1", vm.VirtualAccountTypeTimelock, "newvirtualaccount2") require.NoError(t, err) assert.Equal(t, "memoryaccount1", memoryAccount) assert.True(t, freedIndex2 == 42 || freedIndex2 == 66) assert.NotEqual(t, freedIndex1, freedIndex2) - _, _, err = s.ReserveMemory(ctx, "vm1", cvm.VirtualAccountTypeTimelock, "newvirtualaccount3") + _, _, err = s.ReserveMemory(ctx, "vm1", vm.VirtualAccountTypeTimelock, "newvirtualaccount3") assert.Equal(t, ram.ErrNoFreeMemory, err) }) } diff --git a/ocp/data/cvm/ram/util.go b/ocp/data/vm/ram/util.go similarity index 76% rename from ocp/data/cvm/ram/util.go rename to ocp/data/vm/ram/util.go index d2990e9..dc4e5ae 100644 --- a/ocp/data/cvm/ram/util.go +++ b/ocp/data/vm/ram/util.go @@ -3,11 +3,11 @@ package ram import ( "math" - "github.com/code-payments/ocp-server/solana/cvm" + "github.com/code-payments/ocp-server/solana/vm" ) func GetActualCapcity(record *Record) uint16 { - sizeInMemory := int(cvm.GetVirtualAccountSizeInMemory(record.StoredAccountType)) + sizeInMemory := int(vm.GetVirtualAccountSizeInMemory(record.StoredAccountType)) pagesPerAccount := math.Ceil(1 / (float64(record.PageSize) / float64(sizeInMemory))) availablePerSector := int(record.NumPages) / int(pagesPerAccount) maxAvailableAcrossSectors := uint16(record.NumSectors) * uint16(availablePerSector) diff --git a/ocp/data/cvm/ram/util_test.go b/ocp/data/vm/ram/util_test.go similarity index 64% rename from ocp/data/cvm/ram/util_test.go rename to ocp/data/vm/ram/util_test.go index 2749db6..5f0fca9 100644 --- a/ocp/data/cvm/ram/util_test.go +++ b/ocp/data/vm/ram/util_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/code-payments/ocp-server/solana/cvm" + "github.com/code-payments/ocp-server/solana/vm" ) func TestGetActualCapcity(t *testing.T) { @@ -20,28 +20,28 @@ func TestGetActualCapcity(t *testing.T) { capacity: 1000, numSectors: 2, numPages: 50, - pageSize: uint8(cvm.GetVirtualAccountSizeInMemory(cvm.VirtualAccountTypeTimelock)), + pageSize: uint8(vm.GetVirtualAccountSizeInMemory(vm.VirtualAccountTypeTimelock)), expected: 100, }, { capacity: 10, numSectors: 2, numPages: 50, - pageSize: uint8(cvm.GetVirtualAccountSizeInMemory(cvm.VirtualAccountTypeTimelock)), + pageSize: uint8(vm.GetVirtualAccountSizeInMemory(vm.VirtualAccountTypeTimelock)), expected: 10, }, { capacity: 1000, numSectors: 2, numPages: 50, - pageSize: uint8(cvm.GetVirtualAccountSizeInMemory(cvm.VirtualAccountTypeTimelock)) - 1, + pageSize: uint8(vm.GetVirtualAccountSizeInMemory(vm.VirtualAccountTypeTimelock)) - 1, expected: 50, }, { capacity: 1000, numSectors: 2, numPages: 50, - pageSize: uint8(cvm.GetVirtualAccountSizeInMemory(cvm.VirtualAccountTypeTimelock)) / 3, + pageSize: uint8(vm.GetVirtualAccountSizeInMemory(vm.VirtualAccountTypeTimelock)) / 3, expected: 24, }, } { @@ -50,7 +50,7 @@ func TestGetActualCapcity(t *testing.T) { NumSectors: tc.numSectors, NumPages: tc.numPages, PageSize: tc.pageSize, - StoredAccountType: cvm.VirtualAccountTypeTimelock, + StoredAccountType: vm.VirtualAccountTypeTimelock, } actual := GetActualCapcity(record) assert.Equal(t, tc.expected, actual) diff --git a/ocp/data/cvm/storage/account.go b/ocp/data/vm/storage/account.go similarity index 100% rename from ocp/data/cvm/storage/account.go rename to ocp/data/vm/storage/account.go diff --git a/ocp/data/cvm/storage/memory/store.go b/ocp/data/vm/storage/memory/store.go similarity index 89% rename from ocp/data/cvm/storage/memory/store.go rename to ocp/data/vm/storage/memory/store.go index 0f11f80..913d689 100644 --- a/ocp/data/cvm/storage/memory/store.go +++ b/ocp/data/vm/storage/memory/store.go @@ -5,7 +5,7 @@ import ( "sync" "time" - "github.com/code-payments/ocp-server/ocp/data/cvm/storage" + "github.com/code-payments/ocp-server/ocp/data/vm/storage" ) type store struct { @@ -15,14 +15,14 @@ type store struct { storedAccounts map[string]struct{} } -// New returns a new in memory cvm.storage.Store +// New returns a new in memory vm.storage.Store func New() storage.Store { return &store{ storedAccounts: make(map[string]struct{}), } } -// InitializeStorage implements cvm.storage.Store.InitializeStorage +// InitializeStorage implements vm.storage.Store.InitializeStorage func (s *store) InitializeStorage(_ context.Context, record *storage.Record) error { if err := record.Validate(); err != nil { return err @@ -51,7 +51,7 @@ func (s *store) InitializeStorage(_ context.Context, record *storage.Record) err return nil } -// FindAnyWithAvailableCapacity implements cvm.storage.Store.FindAnyWithAvailableCapacity +// FindAnyWithAvailableCapacity implements vm.storage.Store.FindAnyWithAvailableCapacity func (s *store) FindAnyWithAvailableCapacity(_ context.Context, vm string, purpose storage.Purpose, minCapacity uint64) (*storage.Record, error) { s.mu.Lock() defer s.mu.Unlock() @@ -67,7 +67,7 @@ func (s *store) FindAnyWithAvailableCapacity(_ context.Context, vm string, purpo return &cloned, nil } -// ReserveStorage implements cvm.storage.Store.ReserveStorage +// ReserveStorage implements vm.storage.Store.ReserveStorage func (s *store) ReserveStorage(_ context.Context, vm string, purpose storage.Purpose, address string) (string, error) { s.mu.Lock() defer s.mu.Unlock() diff --git a/ocp/data/cvm/storage/memory/store_test.go b/ocp/data/vm/storage/memory/store_test.go similarity index 75% rename from ocp/data/cvm/storage/memory/store_test.go rename to ocp/data/vm/storage/memory/store_test.go index 8cba14f..0f7e9e3 100644 --- a/ocp/data/cvm/storage/memory/store_test.go +++ b/ocp/data/vm/storage/memory/store_test.go @@ -3,7 +3,7 @@ package memory import ( "testing" - "github.com/code-payments/ocp-server/ocp/data/cvm/storage/tests" + "github.com/code-payments/ocp-server/ocp/data/vm/storage/tests" ) func TestVmStorageMemoryStore(t *testing.T) { diff --git a/ocp/data/cvm/storage/postgres/model.go b/ocp/data/vm/storage/postgres/model.go similarity index 98% rename from ocp/data/cvm/storage/postgres/model.go rename to ocp/data/vm/storage/postgres/model.go index 732ffec..31c1e76 100644 --- a/ocp/data/cvm/storage/postgres/model.go +++ b/ocp/data/vm/storage/postgres/model.go @@ -7,8 +7,8 @@ import ( "github.com/jmoiron/sqlx" - "github.com/code-payments/ocp-server/ocp/data/cvm/storage" pgutil "github.com/code-payments/ocp-server/database/postgres" + "github.com/code-payments/ocp-server/ocp/data/vm/storage" ) const ( diff --git a/ocp/data/cvm/storage/postgres/store.go b/ocp/data/vm/storage/postgres/store.go similarity index 85% rename from ocp/data/cvm/storage/postgres/store.go rename to ocp/data/vm/storage/postgres/store.go index 568d9f5..5b9db99 100644 --- a/ocp/data/cvm/storage/postgres/store.go +++ b/ocp/data/vm/storage/postgres/store.go @@ -6,7 +6,7 @@ import ( "github.com/jmoiron/sqlx" - "github.com/code-payments/ocp-server/ocp/data/cvm/storage" + "github.com/code-payments/ocp-server/ocp/data/vm/storage" ) type store struct { @@ -41,7 +41,7 @@ func (s *store) InitializeStorage(ctx context.Context, record *storage.Record) e return nil } -// FindAnyWithAvailableCapacity implements cvm.storage.Store.FindAnyWithAvailableCapacity +// FindAnyWithAvailableCapacity implements vm.storage.Store.FindAnyWithAvailableCapacity func (s *store) FindAnyWithAvailableCapacity(ctx context.Context, vm string, purpose storage.Purpose, minCapacity uint64) (*storage.Record, error) { model, err := dbFindAnyWithAvailableCapacity(ctx, s.db, vm, purpose, minCapacity) if err != nil { @@ -50,7 +50,7 @@ func (s *store) FindAnyWithAvailableCapacity(ctx context.Context, vm string, pur return fromAccountModel(model), nil } -// ReserveStorage implements cvm.storage.Store.ReserveStorage +// ReserveStorage implements vm.storage.Store.ReserveStorage func (s *store) ReserveStorage(ctx context.Context, vm string, purpose storage.Purpose, address string) (string, error) { return dbReserveStorage(ctx, s.db, vm, purpose, address) } diff --git a/ocp/data/cvm/storage/postgres/store_test.go b/ocp/data/vm/storage/postgres/store_test.go similarity index 95% rename from ocp/data/cvm/storage/postgres/store_test.go rename to ocp/data/vm/storage/postgres/store_test.go index 5b81c5b..b828de1 100644 --- a/ocp/data/cvm/storage/postgres/store_test.go +++ b/ocp/data/vm/storage/postgres/store_test.go @@ -8,8 +8,8 @@ import ( "github.com/ory/dockertest/v3" "go.uber.org/zap" - "github.com/code-payments/ocp-server/ocp/data/cvm/storage" - "github.com/code-payments/ocp-server/ocp/data/cvm/storage/tests" + "github.com/code-payments/ocp-server/ocp/data/vm/storage" + "github.com/code-payments/ocp-server/ocp/data/vm/storage/tests" postgrestest "github.com/code-payments/ocp-server/database/postgres/test" diff --git a/ocp/data/cvm/storage/store.go b/ocp/data/vm/storage/store.go similarity index 100% rename from ocp/data/cvm/storage/store.go rename to ocp/data/vm/storage/store.go diff --git a/ocp/data/cvm/storage/tests/tests.go b/ocp/data/vm/storage/tests/tests.go similarity index 97% rename from ocp/data/cvm/storage/tests/tests.go rename to ocp/data/vm/storage/tests/tests.go index 6e6caa0..01e8c9e 100644 --- a/ocp/data/cvm/storage/tests/tests.go +++ b/ocp/data/vm/storage/tests/tests.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/code-payments/ocp-server/ocp/data/cvm/storage" + "github.com/code-payments/ocp-server/ocp/data/vm/storage" ) func RunTests(t *testing.T, s storage.Store, teardown func()) { diff --git a/ocp/rpc/transaction/action_handler.go b/ocp/rpc/transaction/action_handler.go index 1de2134..eecfad3 100644 --- a/ocp/rpc/transaction/action_handler.go +++ b/ocp/rpc/transaction/action_handler.go @@ -18,15 +18,15 @@ import ( "github.com/code-payments/ocp-server/ocp/data/timelock" "github.com/code-payments/ocp-server/pointer" "github.com/code-payments/ocp-server/solana" - "github.com/code-payments/ocp-server/solana/cvm" + "github.com/code-payments/ocp-server/solana/vm" ) type newFulfillmentMetadata struct { // Signature metadata requiresClientSignature bool - expectedSigner *common.Account // Must be null if the requiresClientSignature is false - virtualIxnHash *cvm.CompactMessage // Must be null if the requiresClientSignature is false + expectedSigner *common.Account // Must be null if the requiresClientSignature is false + virtualIxnHash *vm.CompactMessage // Must be null if the requiresClientSignature is false // Additional metadata to add to the action and fulfillment record, which relates // specifically to the transaction or virtual instruction within the context of @@ -315,12 +315,12 @@ func (h *NoPrivacyTransferActionHandler) GetFulfillmentMetadata( ) (*newFulfillmentMetadata, error) { switch index { case 0: - virtualIxnHash := cvm.GetCompactTransferMessage(&cvm.GetCompactTransferMessageArgs{ + virtualIxnHash := vm.GetCompactTransferMessage(&vm.GetCompactTransferMessageArgs{ Source: h.source.Vault.PublicKey().ToBytes(), Destination: h.destination.PublicKey().ToBytes(), Amount: h.amount, NonceAddress: nonce.PublicKey().ToBytes(), - NonceValue: cvm.Hash(bh), + NonceValue: vm.Hash(bh), }) return &newFulfillmentMetadata{ @@ -430,11 +430,11 @@ func (h *NoPrivacyWithdrawActionHandler) GetFulfillmentMetadata( ) (*newFulfillmentMetadata, error) { switch index { case 0: - virtualIxnHash := cvm.GetCompactWithdrawMessage(&cvm.GetCompactWithdrawMessageArgs{ + virtualIxnHash := vm.GetCompactWithdrawMessage(&vm.GetCompactWithdrawMessageArgs{ Source: h.source.Vault.PublicKey().ToBytes(), Destination: h.destination.PublicKey().ToBytes(), NonceAddress: nonce.PublicKey().ToBytes(), - NonceValue: cvm.Hash(bh), + NonceValue: vm.Hash(bh), }) var intentOrderingIndexOverride *uint64 diff --git a/ocp/rpc/transaction/airdrop.go b/ocp/rpc/transaction/airdrop.go index 1a347f0..87af475 100644 --- a/ocp/rpc/transaction/airdrop.go +++ b/ocp/rpc/transaction/airdrop.go @@ -30,7 +30,7 @@ import ( "github.com/code-payments/ocp-server/ocp/data/nonce" "github.com/code-payments/ocp-server/ocp/transaction" "github.com/code-payments/ocp-server/pointer" - "github.com/code-payments/ocp-server/solana/cvm" + "github.com/code-payments/ocp-server/solana/vm" ) type AirdropType uint8 @@ -271,7 +271,7 @@ func (s *transactionServer) airdrop(ctx context.Context, intentId string, owner // have a proper client call SubmitIntent in a worker. noncePool, err := transaction.SelectNoncePool( - nonce.EnvironmentCvm, + nonce.EnvironmentVm, common.CoreMintVmAccount.PublicKey().ToBase58(), nonce.PurposeClientIntent, s.noncePools..., @@ -289,12 +289,12 @@ func (s *transactionServer) airdrop(ctx context.Context, intentId string, owner selectedNonce.ReleaseIfNotReserved(ctx) }() - vixnHash := cvm.GetCompactTransferMessage(&cvm.GetCompactTransferMessageArgs{ + vixnHash := vm.GetCompactTransferMessage(&vm.GetCompactTransferMessageArgs{ Source: s.airdropper.Vault.PublicKey().ToBytes(), Destination: destination.PublicKey().ToBytes(), Amount: quarkAmount, NonceAddress: selectedNonce.Account.PublicKey().ToBytes(), - NonceValue: cvm.Hash(selectedNonce.Blockhash), + NonceValue: vm.Hash(selectedNonce.Blockhash), }) virtualSig := ed25519.Sign(s.airdropper.VaultOwner.PrivateKey().ToBytes(), vixnHash[:]) diff --git a/ocp/rpc/transaction/errors.go b/ocp/rpc/transaction/errors.go index b01db84..cf2f6d8 100644 --- a/ocp/rpc/transaction/errors.go +++ b/ocp/rpc/transaction/errors.go @@ -15,7 +15,7 @@ import ( "github.com/code-payments/ocp-server/ocp/data/intent" "github.com/code-payments/ocp-server/ocp/transaction" "github.com/code-payments/ocp-server/solana" - "github.com/code-payments/ocp-server/solana/cvm" + "github.com/code-payments/ocp-server/solana/vm" ) const ( @@ -186,7 +186,7 @@ func toInvalidTxnSignatureErrorDetails( func toInvalidVirtualIxnSignatureErrorDetails( actionId uint32, - virtualIxnHash cvm.CompactMessage, + virtualIxnHash vm.CompactMessage, signature *commonpb.Signature, ) *transactionpb.ErrorDetails { return &transactionpb.ErrorDetails{ diff --git a/ocp/rpc/transaction/intent.go b/ocp/rpc/transaction/intent.go index 6a471e4..ce6aa86 100644 --- a/ocp/rpc/transaction/intent.go +++ b/ocp/rpc/transaction/intent.go @@ -32,7 +32,7 @@ import ( "github.com/code-payments/ocp-server/pointer" "github.com/code-payments/ocp-server/protoutil" "github.com/code-payments/ocp-server/solana" - "github.com/code-payments/ocp-server/solana/cvm" + "github.com/code-payments/ocp-server/solana/vm" ) func (s *transactionServer) SubmitIntent(streamer transactionpb.Transaction_SubmitIntentServer) error { @@ -318,7 +318,7 @@ func (s *transactionServer) SubmitIntent(streamer transactionpb.Transaction_Subm requiresClientSignature bool expectedSigner *common.Account - virtualIxnHash *cvm.CompactMessage + virtualIxnHash *vm.CompactMessage intentOrderingIndexOverriden bool } @@ -401,7 +401,7 @@ func (s *transactionServer) SubmitIntent(streamer transactionpb.Transaction_Subm requiresNonce, vmAccount := actionHandler.RequiresNonce(j) if requiresNonce { noncePool, err := transaction.SelectNoncePool( - nonce.EnvironmentCvm, + nonce.EnvironmentVm, vmAccount.PublicKey().ToBase58(), nonce.PurposeClientIntent, s.noncePools..., diff --git a/ocp/rpc/transaction/server.go b/ocp/rpc/transaction/server.go index 6df2a00..8a6516f 100644 --- a/ocp/rpc/transaction/server.go +++ b/ocp/rpc/transaction/server.go @@ -65,7 +65,7 @@ func NewTransactionServer( if !conf.disableSubmitIntent.Get(ctx) { _, err := transaction.SelectNoncePool( - nonce.EnvironmentCvm, + nonce.EnvironmentVm, common.CoreMintVmAccount.PublicKey().ToBase58(), nonce.PurposeClientIntent, noncePools..., diff --git a/ocp/rpc/transaction/swap_handler.go b/ocp/rpc/transaction/swap_handler.go index 67eb622..faaaa41 100644 --- a/ocp/rpc/transaction/swap_handler.go +++ b/ocp/rpc/transaction/swap_handler.go @@ -7,14 +7,14 @@ import ( "github.com/code-payments/ocp-server/ocp/common" ocp_data "github.com/code-payments/ocp-server/ocp/data" - "github.com/code-payments/ocp-server/ocp/vm" + vm_util "github.com/code-payments/ocp-server/ocp/vm" "github.com/code-payments/ocp-server/solana" compute_budget "github.com/code-payments/ocp-server/solana/computebudget" "github.com/code-payments/ocp-server/solana/currencycreator" - "github.com/code-payments/ocp-server/solana/cvm" "github.com/code-payments/ocp-server/solana/memo" "github.com/code-payments/ocp-server/solana/system" "github.com/code-payments/ocp-server/solana/token" + "github.com/code-payments/ocp-server/solana/vm" ) // todo: Move transaction-related stuff to the transaction utility package @@ -103,7 +103,7 @@ func (h *CurrencyCreatorBuySwapHandler) MakeInstructions(ctx context.Context) ([ return nil, err } - h.memoryAccount, h.memoryIndex, err = vm.GetVirtualTimelockAccountLocationInMemory(ctx, h.vmIndexerClient, destinationVmConfig.Vm, h.buyer) + h.memoryAccount, h.memoryIndex, err = vm_util.GetVirtualTimelockAccountLocationInMemory(ctx, h.vmIndexerClient, destinationVmConfig.Vm, h.buyer) if err != nil { return nil, err } @@ -131,8 +131,8 @@ func (h *CurrencyCreatorBuySwapHandler) MakeInstructions(ctx context.Context) ([ return nil, err } - transferFromSourceVmSwapAtaIxn := cvm.NewTransferForSwapInstruction( - &cvm.TransferForSwapInstructionAccounts{ + transferFromSourceVmSwapAtaIxn := vm.NewTransferForSwapInstruction( + &vm.TransferForSwapInstructionAccounts{ VmAuthority: sourceVmConfig.Authority.PublicKey().ToBytes(), Vm: sourceVmConfig.Vm.PublicKey().ToBytes(), Swapper: h.buyer.PublicKey().ToBytes(), @@ -140,7 +140,7 @@ func (h *CurrencyCreatorBuySwapHandler) MakeInstructions(ctx context.Context) ([ SwapAta: sourceTimelockAccounts.VmSwapAccounts.Ata.PublicKey().ToBytes(), Destination: temporaryCoreMintAta.PublicKey().ToBytes(), }, - &cvm.TransferForSwapInstructionArgs{ + &vm.TransferForSwapInstructionArgs{ Amount: h.amount, Bump: sourceTimelockAccounts.VmSwapAccounts.PdaBump, }, @@ -178,8 +178,8 @@ func (h *CurrencyCreatorBuySwapHandler) MakeInstructions(ctx context.Context) ([ h.temporaryHolder.PublicKey().ToBytes(), ) - closeSourceVmSwapAccountIfEmptyIxn := cvm.NewCloseSwapAccountIfEmptyInstruction( - &cvm.CloseSwapAccountIfEmptyInstructionAccounts{ + closeSourceVmSwapAccountIfEmptyIxn := vm.NewCloseSwapAccountIfEmptyInstruction( + &vm.CloseSwapAccountIfEmptyInstructionAccounts{ VmAuthority: sourceVmConfig.Authority.PublicKey().ToBytes(), Vm: sourceVmConfig.Vm.PublicKey().ToBytes(), Swapper: h.buyer.PublicKey().ToBytes(), @@ -187,7 +187,7 @@ func (h *CurrencyCreatorBuySwapHandler) MakeInstructions(ctx context.Context) ([ SwapAta: sourceTimelockAccounts.VmSwapAccounts.Ata.PublicKey().ToBytes(), Destination: common.GetSubsidizer().PublicKey().ToBytes(), }, - &cvm.CloseSwapAccountIfEmptyInstructionArgs{ + &vm.CloseSwapAccountIfEmptyInstructionArgs{ Bump: sourceTimelockAccounts.VmSwapAccounts.PdaBump, }, ) @@ -283,7 +283,7 @@ func (h *CurrencyCreatorSellSwapHandler) MakeInstructions(ctx context.Context) ( return nil, err } - h.memoryAccount, h.memoryIndex, err = vm.GetVirtualTimelockAccountLocationInMemory(ctx, h.vmIndexerClient, destinationVmConfig.Vm, h.seller) + h.memoryAccount, h.memoryIndex, err = vm_util.GetVirtualTimelockAccountLocationInMemory(ctx, h.vmIndexerClient, destinationVmConfig.Vm, h.seller) if err != nil { return nil, err } @@ -301,8 +301,8 @@ func (h *CurrencyCreatorSellSwapHandler) MakeInstructions(ctx context.Context) ( return nil, err } - transferFromSourceVmSwapAtaIxn := cvm.NewTransferForSwapInstruction( - &cvm.TransferForSwapInstructionAccounts{ + transferFromSourceVmSwapAtaIxn := vm.NewTransferForSwapInstruction( + &vm.TransferForSwapInstructionAccounts{ VmAuthority: sourceVmConfig.Authority.PublicKey().ToBytes(), Vm: sourceVmConfig.Vm.PublicKey().ToBytes(), Swapper: h.seller.PublicKey().ToBytes(), @@ -310,7 +310,7 @@ func (h *CurrencyCreatorSellSwapHandler) MakeInstructions(ctx context.Context) ( SwapAta: sourceTimelockAccounts.VmSwapAccounts.Ata.PublicKey().ToBytes(), Destination: temporarySourceCurrencyAta.PublicKey().ToBytes(), }, - &cvm.TransferForSwapInstructionArgs{ + &vm.TransferForSwapInstructionArgs{ Amount: h.amount, Bump: sourceTimelockAccounts.VmSwapAccounts.PdaBump, }, @@ -348,8 +348,8 @@ func (h *CurrencyCreatorSellSwapHandler) MakeInstructions(ctx context.Context) ( h.temporaryHolder.PublicKey().ToBytes(), ) - closeSourceVmSwapAccountIfEmptyIxn := cvm.NewCloseSwapAccountIfEmptyInstruction( - &cvm.CloseSwapAccountIfEmptyInstructionAccounts{ + closeSourceVmSwapAccountIfEmptyIxn := vm.NewCloseSwapAccountIfEmptyInstruction( + &vm.CloseSwapAccountIfEmptyInstructionAccounts{ VmAuthority: sourceVmConfig.Authority.PublicKey().ToBytes(), Vm: sourceVmConfig.Vm.PublicKey().ToBytes(), Swapper: h.seller.PublicKey().ToBytes(), @@ -357,7 +357,7 @@ func (h *CurrencyCreatorSellSwapHandler) MakeInstructions(ctx context.Context) ( SwapAta: sourceTimelockAccounts.VmSwapAccounts.Ata.PublicKey().ToBytes(), Destination: common.GetSubsidizer().PublicKey().ToBytes(), }, - &cvm.CloseSwapAccountIfEmptyInstructionArgs{ + &vm.CloseSwapAccountIfEmptyInstructionArgs{ Bump: sourceTimelockAccounts.VmSwapAccounts.PdaBump, }, ) @@ -456,7 +456,7 @@ func (h *CurrencyCreatorBuySellSwapHandler) MakeInstructions(ctx context.Context return nil, err } - h.memoryAccount, h.memoryIndex, err = vm.GetVirtualTimelockAccountLocationInMemory(ctx, h.vmIndexerClient, destinationVmConfig.Vm, h.swapper) + h.memoryAccount, h.memoryIndex, err = vm_util.GetVirtualTimelockAccountLocationInMemory(ctx, h.vmIndexerClient, destinationVmConfig.Vm, h.swapper) if err != nil { return nil, err } @@ -497,8 +497,8 @@ func (h *CurrencyCreatorBuySellSwapHandler) MakeInstructions(ctx context.Context return nil, err } - transferFromSourceVmSwapAtaIxn := cvm.NewTransferForSwapInstruction( - &cvm.TransferForSwapInstructionAccounts{ + transferFromSourceVmSwapAtaIxn := vm.NewTransferForSwapInstruction( + &vm.TransferForSwapInstructionAccounts{ VmAuthority: sourceVmConfig.Authority.PublicKey().ToBytes(), Vm: sourceVmConfig.Vm.PublicKey().ToBytes(), Swapper: h.swapper.PublicKey().ToBytes(), @@ -506,7 +506,7 @@ func (h *CurrencyCreatorBuySellSwapHandler) MakeInstructions(ctx context.Context SwapAta: sourceTimelockAccounts.VmSwapAccounts.Ata.PublicKey().ToBytes(), Destination: temporarySourceCurrencyAta.PublicKey().ToBytes(), }, - &cvm.TransferForSwapInstructionArgs{ + &vm.TransferForSwapInstructionArgs{ Amount: h.amount, Bump: sourceTimelockAccounts.VmSwapAccounts.PdaBump, }, @@ -570,8 +570,8 @@ func (h *CurrencyCreatorBuySellSwapHandler) MakeInstructions(ctx context.Context h.temporaryHolder.PublicKey().ToBytes(), ) - closeSourceVmSwapAccountIfEmptyIxn := cvm.NewCloseSwapAccountIfEmptyInstruction( - &cvm.CloseSwapAccountIfEmptyInstructionAccounts{ + closeSourceVmSwapAccountIfEmptyIxn := vm.NewCloseSwapAccountIfEmptyInstruction( + &vm.CloseSwapAccountIfEmptyInstructionAccounts{ VmAuthority: sourceVmConfig.Authority.PublicKey().ToBytes(), Vm: sourceVmConfig.Vm.PublicKey().ToBytes(), Swapper: h.swapper.PublicKey().ToBytes(), @@ -579,7 +579,7 @@ func (h *CurrencyCreatorBuySellSwapHandler) MakeInstructions(ctx context.Context SwapAta: sourceTimelockAccounts.VmSwapAccounts.Ata.PublicKey().ToBytes(), Destination: common.GetSubsidizer().PublicKey().ToBytes(), }, - &cvm.CloseSwapAccountIfEmptyInstructionArgs{ + &vm.CloseSwapAccountIfEmptyInstructionArgs{ Bump: sourceTimelockAccounts.VmSwapAccounts.PdaBump, }, ) diff --git a/ocp/transaction/nonce_pool_test.go b/ocp/transaction/nonce_pool_test.go index 90da109..a459f42 100644 --- a/ocp/transaction/nonce_pool_test.go +++ b/ocp/transaction/nonce_pool_test.go @@ -46,7 +46,7 @@ func testLocalNoncePoolHappyPath(nt *localNoncePoolTest) { nt.initializeNonces(nt.pool.opts.desiredPoolSize, nonce.EnvironmentSolana, nonce.EnvironmentInstanceSolanaMainnet, nonce.PurposeClientIntent) nt.initializeNonces(nt.pool.opts.desiredPoolSize, nonce.EnvironmentSolana, nonce.EnvironmentInstanceSolanaMainnet, nonce.PurposeOnDemandTransaction) nt.initializeNonces(nt.pool.opts.desiredPoolSize, nonce.EnvironmentSolana, nonce.EnvironmentInstanceSolanaDevnet, nonce.PurposeClientIntent) - nt.initializeNonces(nt.pool.opts.desiredPoolSize, nonce.EnvironmentCvm, testutil.NewRandomAccount(nt.t).PublicKey().ToBase58(), nonce.PurposeClientIntent) + nt.initializeNonces(nt.pool.opts.desiredPoolSize, nonce.EnvironmentVm, testutil.NewRandomAccount(nt.t).PublicKey().ToBase58(), nonce.PurposeClientIntent) ctx := context.Background() diff --git a/ocp/transaction/transaction.go b/ocp/transaction/transaction.go index 5b08ea7..f8d19a6 100644 --- a/ocp/transaction/transaction.go +++ b/ocp/transaction/transaction.go @@ -9,8 +9,8 @@ import ( "github.com/code-payments/ocp-server/ocp/common" "github.com/code-payments/ocp-server/solana" compute_budget "github.com/code-payments/ocp-server/solana/computebudget" - "github.com/code-payments/ocp-server/solana/cvm" "github.com/code-payments/ocp-server/solana/token" + "github.com/code-payments/ocp-server/solana/vm" ) // todo: The argument sizes are blowing out of proportion, though there's likely @@ -83,16 +83,16 @@ func MakeCompressAccountTransaction( signature := ed25519.Sign(vmConfig.Authority.PrivateKey().ToBytes(), hashedVirtualAccountState) - compressInstruction := cvm.NewCompressInstruction( - &cvm.CompressInstructionAccounts{ + compressInstruction := vm.NewCompressInstruction( + &vm.CompressInstructionAccounts{ VmAuthority: vmConfig.Authority.PublicKey().ToBytes(), Vm: vmConfig.Vm.PublicKey().ToBytes(), VmMemory: memory.PublicKey().ToBytes(), VmStorage: storage.PublicKey().ToBytes(), }, - &cvm.CompressInstructionArgs{ + &vm.CompressInstructionArgs{ AccountIndex: accountIndex, - Signature: cvm.Signature(signature), + Signature: vm.Signature(signature), }, ) @@ -125,19 +125,19 @@ func MakeInternalWithdrawTransaction( return solana.Transaction{}, err } - vixn := cvm.NewWithdrawVirtualInstruction(&cvm.WithdrawVirtualInstructionArgs{ - Signature: cvm.Signature(virtualSignature), + vixn := vm.NewWithdrawVirtualInstruction(&vm.WithdrawVirtualInstructionArgs{ + Signature: vm.Signature(virtualSignature), }) - execInstruction := cvm.NewExecInstruction( - &cvm.ExecInstructionAccounts{ + execInstruction := vm.NewExecInstruction( + &vm.ExecInstructionAccounts{ VmAuthority: vmConfig.Authority.PublicKey().ToBytes(), Vm: vmConfig.Vm.PublicKey().ToBytes(), VmMemA: mergedMemoryBanks.A, VmMemB: mergedMemoryBanks.B, VmMemC: mergedMemoryBanks.C, }, - &cvm.ExecInstructionArgs{ + &vm.ExecInstructionArgs{ Opcode: vixn.Opcode, MemIndices: []uint16{nonceIndex, sourceIndex, destinationIndex}, MemBanks: mergedMemoryBanks.Indices, @@ -177,12 +177,12 @@ func MakeExternalWithdrawTransaction( externalAddressPublicKeyBytes := ed25519.PublicKey(externalDestination.PublicKey().ToBytes()) - vixn := cvm.NewWithdrawVirtualInstruction(&cvm.WithdrawVirtualInstructionArgs{ - Signature: cvm.Signature(virtualSignature), + vixn := vm.NewWithdrawVirtualInstruction(&vm.WithdrawVirtualInstructionArgs{ + Signature: vm.Signature(virtualSignature), }) - execInstruction := cvm.NewExecInstruction( - &cvm.ExecInstructionAccounts{ + execInstruction := vm.NewExecInstruction( + &vm.ExecInstructionAccounts{ VmAuthority: vmConfig.Authority.PublicKey().ToBytes(), Vm: vmConfig.Vm.PublicKey().ToBytes(), VmMemA: mergedMemoryBanks.A, @@ -190,7 +190,7 @@ func MakeExternalWithdrawTransaction( VmOmnibus: &vmOmnibusPublicKeyBytes, ExternalAddress: &externalAddressPublicKeyBytes, }, - &cvm.ExecInstructionArgs{ + &vm.ExecInstructionArgs{ Opcode: vixn.Opcode, MemIndices: []uint16{nonceIndex, sourceIndex}, MemBanks: mergedMemoryBanks.Indices, @@ -229,20 +229,20 @@ func MakeInternalTransferWithAuthorityTransaction( return solana.Transaction{}, err } - vixn := cvm.NewTransferVirtualInstruction(&cvm.TransferVirtualInstructionArgs{ + vixn := vm.NewTransferVirtualInstruction(&vm.TransferVirtualInstructionArgs{ Amount: quarks, - Signature: cvm.Signature(virtualSignature), + Signature: vm.Signature(virtualSignature), }) - execInstruction := cvm.NewExecInstruction( - &cvm.ExecInstructionAccounts{ + execInstruction := vm.NewExecInstruction( + &vm.ExecInstructionAccounts{ VmAuthority: vmConfig.Authority.PublicKey().ToBytes(), Vm: vmConfig.Vm.PublicKey().ToBytes(), VmMemA: mergedMemoryBanks.A, VmMemB: mergedMemoryBanks.B, VmMemC: mergedMemoryBanks.C, }, - &cvm.ExecInstructionArgs{ + &vm.ExecInstructionArgs{ Opcode: vixn.Opcode, MemIndices: []uint16{nonceIndex, sourceIndex, destinationIndex}, MemBanks: mergedMemoryBanks.Indices, @@ -287,13 +287,13 @@ func MakeExternalTransferWithAuthorityTransaction( vmOmnibusPublicKeyBytes := ed25519.PublicKey(vmConfig.Omnibus.PublicKey().ToBytes()) - vixn := cvm.NewExternalTransferVirtualInstruction(&cvm.TransferVirtualInstructionArgs{ + vixn := vm.NewExternalTransferVirtualInstruction(&vm.TransferVirtualInstructionArgs{ Amount: quarks, - Signature: cvm.Signature(virtualSignature), + Signature: vm.Signature(virtualSignature), }) - execInstruction := cvm.NewExecInstruction( - &cvm.ExecInstructionAccounts{ + execInstruction := vm.NewExecInstruction( + &vm.ExecInstructionAccounts{ VmAuthority: vmConfig.Authority.PublicKey().ToBytes(), Vm: vmConfig.Vm.PublicKey().ToBytes(), VmMemA: mergedMemoryBanks.A, @@ -301,7 +301,7 @@ func MakeExternalTransferWithAuthorityTransaction( VmOmnibus: &vmOmnibusPublicKeyBytes, ExternalAddress: &externalAddressPublicKeyBytes, }, - &cvm.ExecInstructionArgs{ + &vm.ExecInstructionArgs{ Opcode: vixn.Opcode, MemIndices: []uint16{nonceIndex, sourceIndex}, MemBanks: mergedMemoryBanks.Indices, diff --git a/ocp/vm/virtual_account.go b/ocp/vm/virtual_account.go index 7d7d7a8..38ed8f1 100644 --- a/ocp/vm/virtual_account.go +++ b/ocp/vm/virtual_account.go @@ -11,7 +11,7 @@ import ( "github.com/code-payments/ocp-server/ocp/common" ocp_data "github.com/code-payments/ocp-server/ocp/data" "github.com/code-payments/ocp-server/ocp/data/fulfillment" - "github.com/code-payments/ocp-server/solana/cvm" + vm_program "github.com/code-payments/ocp-server/solana/vm" ) func EnsureVirtualTimelockAccountIsInitialized(ctx context.Context, data ocp_data.Provider, vmIndexerClient indexerpb.IndexerClient, mint, owner *common.Account, waitForInitialization bool) error { @@ -62,7 +62,7 @@ func EnsureVirtualTimelockAccountIsInitialized(ctx context.Context, data ocp_dat return errors.New("timed out waiting for initialization") } -func GetVirtualTimelockAccountStateInMemory(ctx context.Context, vmIndexerClient indexerpb.IndexerClient, vm, owner *common.Account) (*cvm.VirtualTimelockAccount, *common.Account, uint16, error) { +func GetVirtualTimelockAccountStateInMemory(ctx context.Context, vmIndexerClient indexerpb.IndexerClient, vm, owner *common.Account) (*vm_program.VirtualTimelockAccount, *common.Account, uint16, error) { resp, err := vmIndexerClient.GetVirtualTimelockAccounts(ctx, &indexerpb.GetVirtualTimelockAccountsRequest{ VmAccount: &indexerpb.Address{Value: vm.PublicKey().ToBytes()}, Owner: &indexerpb.Address{Value: owner.PublicKey().ToBytes()}, @@ -86,9 +86,9 @@ func GetVirtualTimelockAccountStateInMemory(ctx context.Context, vmIndexerClient } protoAccount := resp.Items[0].Account - state := cvm.VirtualTimelockAccount{ + state := vm_program.VirtualTimelockAccount{ Owner: protoAccount.Owner.Value, - Nonce: cvm.Hash(protoAccount.Nonce.Value), + Nonce: vm_program.Hash(protoAccount.Nonce.Value), TokenBump: uint8(protoAccount.TokenBump), UnlockBump: uint8(protoAccount.UnlockBump), @@ -109,7 +109,7 @@ func GetVirtualTimelockAccountLocationInMemory(ctx context.Context, vmIndexerCli return memory, memoryIndex, nil } -func GetVirtualDurableNonceAccountStateInMemory(ctx context.Context, vmIndexerClient indexerpb.IndexerClient, vm, nonce *common.Account) (*cvm.VirtualDurableNonce, *common.Account, uint16, error) { +func GetVirtualDurableNonceAccountStateInMemory(ctx context.Context, vmIndexerClient indexerpb.IndexerClient, vm, nonce *common.Account) (*vm_program.VirtualDurableNonce, *common.Account, uint16, error) { resp, err := vmIndexerClient.GetVirtualDurableNonce(ctx, &indexerpb.GetVirtualDurableNonceRequest{ VmAccount: &indexerpb.Address{Value: vm.PublicKey().ToBytes()}, Address: &indexerpb.Address{Value: nonce.PublicKey().ToBytes()}, @@ -131,9 +131,9 @@ func GetVirtualDurableNonceAccountStateInMemory(ctx context.Context, vmIndexerCl } protoAccount := resp.Item.Account - state := cvm.VirtualDurableNonce{ + state := vm_program.VirtualDurableNonce{ Address: protoAccount.Address.Value, - Value: cvm.Hash(protoAccount.Value.Value), + Value: vm_program.Hash(protoAccount.Value.Value), } return &state, memory, uint16(protoMemory.Index), nil diff --git a/ocp/worker/geyser/external_deposit.go b/ocp/worker/geyser/external_deposit.go index 6ba7832..65ada04 100644 --- a/ocp/worker/geyser/external_deposit.go +++ b/ocp/worker/geyser/external_deposit.go @@ -23,12 +23,12 @@ import ( "github.com/code-payments/ocp-server/ocp/data/intent" "github.com/code-payments/ocp-server/ocp/data/transaction" transaction_util "github.com/code-payments/ocp-server/ocp/transaction" - "github.com/code-payments/ocp-server/ocp/vm" + vm_util "github.com/code-payments/ocp-server/ocp/vm" "github.com/code-payments/ocp-server/retry" "github.com/code-payments/ocp-server/solana" compute_budget "github.com/code-payments/ocp-server/solana/computebudget" - "github.com/code-payments/ocp-server/solana/cvm" "github.com/code-payments/ocp-server/solana/memo" + "github.com/code-payments/ocp-server/solana/vm" ) const ( @@ -100,12 +100,12 @@ func initiateExternalDepositIntoVm(ctx context.Context, data ocp_data.Provider, return errors.Wrap(err, "error getting timelock accounts") } - err = vm.EnsureVirtualTimelockAccountIsInitialized(ctx, data, vmIndexerClient, mint, userAuthority, true) + err = vm_util.EnsureVirtualTimelockAccountIsInitialized(ctx, data, vmIndexerClient, mint, userAuthority, true) if err != nil { return errors.Wrap(err, "error ensuring vta is initialized") } - memoryAccount, memoryIndex, err := vm.GetVirtualTimelockAccountLocationInMemory(ctx, vmIndexerClient, vmConfig.Vm, userAuthority) + memoryAccount, memoryIndex, err := vm_util.GetVirtualTimelockAccountLocationInMemory(ctx, vmIndexerClient, vmConfig.Vm, userAuthority) if err != nil { return errors.Wrap(err, "error getting vta location in memory") } @@ -115,8 +115,8 @@ func initiateExternalDepositIntoVm(ctx context.Context, data ocp_data.Provider, memo.Instruction(codeVmDepositMemoValue), compute_budget.SetComputeUnitPrice(1_000), compute_budget.SetComputeUnitLimit(50_000), - cvm.NewDepositFromPdaInstruction( - &cvm.DepositFromPdaInstructionAccounts{ + vm.NewDepositFromPdaInstruction( + &vm.DepositFromPdaInstructionAccounts{ VmAuthority: vmConfig.Authority.PublicKey().ToBytes(), Vm: vmConfig.Vm.PublicKey().ToBytes(), VmMemory: memoryAccount.PublicKey().ToBytes(), @@ -125,7 +125,7 @@ func initiateExternalDepositIntoVm(ctx context.Context, data ocp_data.Provider, DepositAta: timelockAccounts.VmDepositAccounts.Ata.PublicKey().ToBytes(), VmOmnibus: vmConfig.Omnibus.PublicKey().ToBytes(), }, - &cvm.DepositFromPdaInstructionArgs{ + &vm.DepositFromPdaInstructionArgs{ AccountIndex: memoryIndex, Amount: balance, Bump: timelockAccounts.VmDepositAccounts.PdaBump, diff --git a/ocp/worker/geyser/timelock.go b/ocp/worker/geyser/timelock.go index fa12ede..f924464 100644 --- a/ocp/worker/geyser/timelock.go +++ b/ocp/worker/geyser/timelock.go @@ -8,8 +8,8 @@ import ( ocp_data "github.com/code-payments/ocp-server/ocp/data" "github.com/code-payments/ocp-server/ocp/data/timelock" "github.com/code-payments/ocp-server/solana" - "github.com/code-payments/ocp-server/solana/cvm" timelock_token "github.com/code-payments/ocp-server/solana/timelock/v1" + "github.com/code-payments/ocp-server/solana/vm" ) func updateTimelockAccountRecord(ctx context.Context, data ocp_data.Provider, timelockRecord *timelock.Record) error { @@ -35,7 +35,7 @@ func updateTimelockAccountRecord(ctx context.Context, data ocp_data.Provider, ti return data.SaveTimelock(ctx, timelockRecord) } -func getTimelockUnlockState(ctx context.Context, data ocp_data.Provider, timelockRecord *timelock.Record) (*cvm.UnlockStateAccount, uint64, error) { +func getTimelockUnlockState(ctx context.Context, data ocp_data.Provider, timelockRecord *timelock.Record) (*vm.UnlockStateAccount, uint64, error) { accountInfoRecord, err := data.GetAccountInfoByTokenAddress(ctx, timelockRecord.VaultAddress) if err != nil { return nil, 0, err @@ -64,7 +64,7 @@ func getTimelockUnlockState(ctx context.Context, data ocp_data.Provider, timeloc marshalled, slot, err := data.GetBlockchainAccountDataAfterBlock(ctx, timelockAccounts.Unlock.PublicKey().ToBase58(), timelockRecord.Block) switch err { case nil: - var unlockState cvm.UnlockStateAccount + var unlockState vm.UnlockStateAccount if err = unlockState.Unmarshal(marshalled); err != nil { return nil, 0, err } diff --git a/ocp/worker/nonce/metrics.go b/ocp/worker/nonce/metrics.go index a8adf50..8baeefa 100644 --- a/ocp/worker/nonce/metrics.go +++ b/ocp/worker/nonce/metrics.go @@ -33,11 +33,11 @@ func (p *runtime) metricsGaugeWorker(ctx context.Context) error { nonce.StateInvalid, nonce.StateClaimed, } { - count, err := p.data.GetNonceCountByStateAndPurpose(ctx, nonce.EnvironmentCvm, common.CoreMintVmAccount.PublicKey().ToBase58(), state, nonce.PurposeClientIntent) + count, err := p.data.GetNonceCountByStateAndPurpose(ctx, nonce.EnvironmentVm, common.CoreMintVmAccount.PublicKey().ToBase58(), state, nonce.PurposeClientIntent) if err != nil { continue } - recordNonceCountEvent(ctx, nonce.EnvironmentCvm, common.CoreMintVmAccount.PublicKey().ToBase58(), state, nonce.PurposeClientIntent, count) + recordNonceCountEvent(ctx, nonce.EnvironmentVm, common.CoreMintVmAccount.PublicKey().ToBase58(), state, nonce.PurposeClientIntent, count) count, err = p.data.GetNonceCountByStateAndPurpose(ctx, nonce.EnvironmentSolana, nonce.EnvironmentInstanceSolanaMainnet, state, nonce.PurposeOnDemandTransaction) if err != nil { diff --git a/ocp/worker/nonce/pool.go b/ocp/worker/nonce/pool.go index d75335e..eac39c9 100644 --- a/ocp/worker/nonce/pool.go +++ b/ocp/worker/nonce/pool.go @@ -206,7 +206,7 @@ func (p *runtime) handleUnknown(ctx context.Context, record *nonce.Record) error func (p *runtime) handleReleased(ctx context.Context, record *nonce.Record) error { switch record.Environment { - case nonce.EnvironmentSolana, nonce.EnvironmentCvm: + case nonce.EnvironmentSolana, nonce.EnvironmentVm: default: return errors.Errorf("%s environment not supported for %s state", record.Environment.String(), nonce.StateReleased.String()) } @@ -222,7 +222,7 @@ func (p *runtime) handleReleased(ctx context.Context, record *nonce.Record) erro if err != nil { return err } - case nonce.EnvironmentCvm: + case nonce.EnvironmentVm: fulfillmentRecord, err := p.data.GetFulfillmentByVirtualSignature(ctx, record.Signature) if err != nil { return err @@ -247,8 +247,8 @@ func (p *runtime) handleReleased(ctx context.Context, record *nonce.Record) erro if err != nil { return err } - case nonce.EnvironmentCvm: - nextBlockhash, err = p.getBlockhashFromCvmNonce(ctx, record, txn.Slot) + case nonce.EnvironmentVm: + nextBlockhash, err = p.getBlockhashFromVmNonce(ctx, record, txn.Slot) if err != nil { return err } diff --git a/ocp/worker/nonce/runtime.go b/ocp/worker/nonce/runtime.go index ca1e459..8bd7938 100644 --- a/ocp/worker/nonce/runtime.go +++ b/ocp/worker/nonce/runtime.go @@ -64,7 +64,7 @@ func (p *runtime) Start(ctx context.Context, interval time.Duration) error { }(state) } - // Setup workers to watch for nonce state changes on the CVM side + // Setup workers to watch for nonce state changes on the VM side // // todo: Dynamically detect VMs for _, vm := range []string{ @@ -75,9 +75,9 @@ func (p *runtime) Start(ctx context.Context, interval time.Duration) error { } { go func(vm string, state nonce.State) { - err := p.worker(ctx, nonce.EnvironmentCvm, vm, state, interval) + err := p.worker(ctx, nonce.EnvironmentVm, vm, state, interval) if err != nil && err != context.Canceled { - p.log.With(zap.Error(err)).Warn(fmt.Sprintf("nonce processing loop terminated unexpectedly for env %s, instance %s, state %d", nonce.EnvironmentCvm, vm, state)) + p.log.With(zap.Error(err)).Warn(fmt.Sprintf("nonce processing loop terminated unexpectedly for env %s, instance %s, state %d", nonce.EnvironmentVm, vm, state)) } }(vm, state) diff --git a/ocp/worker/nonce/util.go b/ocp/worker/nonce/util.go index 3a50f9c..f6bf648 100644 --- a/ocp/worker/nonce/util.go +++ b/ocp/worker/nonce/util.go @@ -245,9 +245,9 @@ func (p *runtime) getBlockhashFromSolanaNonce(ctx context.Context, record *nonce return base58.Encode(data.Blockhash), nil } -func (p *runtime) getBlockhashFromCvmNonce(ctx context.Context, record *nonce.Record, slot uint64) (string, error) { - if record.Environment != nonce.EnvironmentCvm { - return "", errors.Errorf("nonce environment is not %s", nonce.EnvironmentCvm.String()) +func (p *runtime) getBlockhashFromVmNonce(ctx context.Context, record *nonce.Record, slot uint64) (string, error) { + if record.Environment != nonce.EnvironmentVm { + return "", errors.Errorf("nonce environment is not %s", nonce.EnvironmentVm.String()) } decodedVmAddress, err := base58.Decode(record.EnvironmentInstance) diff --git a/ocp/worker/sequencer/fulfillment_handler.go b/ocp/worker/sequencer/fulfillment_handler.go index e6cbfee..f92f47b 100644 --- a/ocp/worker/sequencer/fulfillment_handler.go +++ b/ocp/worker/sequencer/fulfillment_handler.go @@ -13,15 +13,15 @@ import ( "github.com/code-payments/ocp-server/ocp/common" ocp_data "github.com/code-payments/ocp-server/ocp/data" "github.com/code-payments/ocp-server/ocp/data/action" - "github.com/code-payments/ocp-server/ocp/data/cvm/storage" "github.com/code-payments/ocp-server/ocp/data/fulfillment" "github.com/code-payments/ocp-server/ocp/data/timelock" "github.com/code-payments/ocp-server/ocp/data/transaction" + "github.com/code-payments/ocp-server/ocp/data/vm/storage" transaction_util "github.com/code-payments/ocp-server/ocp/transaction" - "github.com/code-payments/ocp-server/ocp/vm" + vm_util "github.com/code-payments/ocp-server/ocp/vm" "github.com/code-payments/ocp-server/solana" - "github.com/code-payments/ocp-server/solana/cvm" "github.com/code-payments/ocp-server/solana/token" + "github.com/code-payments/ocp-server/solana/vm" ) type FulfillmentHandler interface { @@ -172,7 +172,7 @@ func (h *InitializeLockedTimelockAccountFulfillmentHandler) MakeOnDemandTransact return nil, nil, errors.New("unexpected timelock vault address") } - memory, accountIndex, err := reserveVmMemory(ctx, h.data, vmConfig.Vm, cvm.VirtualAccountTypeTimelock, timelockAccounts.Vault) + memory, accountIndex, err := reserveVmMemory(ctx, h.data, vmConfig.Vm, vm.VirtualAccountTypeTimelock, timelockAccounts.Vault) if err != nil { return nil, nil, err } @@ -365,12 +365,12 @@ func (h *NoPrivacyTransferWithAuthorityFulfillmentHandler) MakeOnDemandTransacti return nil, nil, err } - nonceMemory, nonceIndex, err := vm.GetVirtualDurableNonceAccountLocationInMemory(ctx, h.vmIndexerClient, vmConfig.Vm, virtualNonce) + nonceMemory, nonceIndex, err := vm_util.GetVirtualDurableNonceAccountLocationInMemory(ctx, h.vmIndexerClient, vmConfig.Vm, virtualNonce) if err != nil { return nil, nil, err } - sourceMemory, sourceIndex, err := vm.GetVirtualTimelockAccountLocationInMemory(ctx, h.vmIndexerClient, vmConfig.Vm, sourceAuthority) + sourceMemory, sourceIndex, err := vm_util.GetVirtualTimelockAccountLocationInMemory(ctx, h.vmIndexerClient, vmConfig.Vm, sourceAuthority) if err != nil { return nil, nil, err } @@ -393,7 +393,7 @@ func (h *NoPrivacyTransferWithAuthorityFulfillmentHandler) MakeOnDemandTransacti return nil, nil, err } - destinationMemory, destinationIndex, err := vm.GetVirtualTimelockAccountLocationInMemory(ctx, h.vmIndexerClient, vmConfig.Vm, destinationAuthority) + destinationMemory, destinationIndex, err := vm_util.GetVirtualTimelockAccountLocationInMemory(ctx, h.vmIndexerClient, vmConfig.Vm, destinationAuthority) if err != nil { return nil, nil, err } @@ -584,12 +584,12 @@ func (h *NoPrivacyWithdrawFulfillmentHandler) MakeOnDemandTransaction(ctx contex return nil, nil, err } - nonceMemory, nonceIndex, err := vm.GetVirtualDurableNonceAccountLocationInMemory(ctx, h.vmIndexerClient, vmConfig.Vm, virtualNonce) + nonceMemory, nonceIndex, err := vm_util.GetVirtualDurableNonceAccountLocationInMemory(ctx, h.vmIndexerClient, vmConfig.Vm, virtualNonce) if err != nil { return nil, nil, err } - sourceMemory, sourceIndex, err := vm.GetVirtualTimelockAccountLocationInMemory(ctx, h.vmIndexerClient, vmConfig.Vm, sourceAuthority) + sourceMemory, sourceIndex, err := vm_util.GetVirtualTimelockAccountLocationInMemory(ctx, h.vmIndexerClient, vmConfig.Vm, sourceAuthority) if err != nil { return nil, nil, err } @@ -612,7 +612,7 @@ func (h *NoPrivacyWithdrawFulfillmentHandler) MakeOnDemandTransaction(ctx contex return nil, nil, err } - destinationMemory, destinationIndex, err := vm.GetVirtualTimelockAccountLocationInMemory(ctx, h.vmIndexerClient, vmConfig.Vm, destinationAuthority) + destinationMemory, destinationIndex, err := vm_util.GetVirtualTimelockAccountLocationInMemory(ctx, h.vmIndexerClient, vmConfig.Vm, destinationAuthority) if err != nil { return nil, nil, err } @@ -774,7 +774,7 @@ func (h *CloseEmptyTimelockAccountFulfillmentHandler) MakeOnDemandTransaction(ct return nil, nil, err } - virtualAccountState, memory, index, err := vm.GetVirtualTimelockAccountStateInMemory(ctx, h.vmIndexerClient, vmConfig.Vm, timelockOwner) + virtualAccountState, memory, index, err := vm_util.GetVirtualTimelockAccountStateInMemory(ctx, h.vmIndexerClient, vmConfig.Vm, timelockOwner) if err != nil { return nil, nil, err } diff --git a/ocp/worker/sequencer/vm.go b/ocp/worker/sequencer/vm.go index b2b1ccc..3f88ce5 100644 --- a/ocp/worker/sequencer/vm.go +++ b/ocp/worker/sequencer/vm.go @@ -7,11 +7,11 @@ import ( "github.com/code-payments/ocp-server/ocp/common" ocp_data "github.com/code-payments/ocp-server/ocp/data" - "github.com/code-payments/ocp-server/ocp/data/cvm/ram" - "github.com/code-payments/ocp-server/ocp/data/cvm/storage" "github.com/code-payments/ocp-server/ocp/data/intent" "github.com/code-payments/ocp-server/ocp/data/timelock" - "github.com/code-payments/ocp-server/solana/cvm" + "github.com/code-payments/ocp-server/ocp/data/vm/ram" + "github.com/code-payments/ocp-server/ocp/data/vm/storage" + "github.com/code-payments/ocp-server/solana/vm" ) // todo: some of these utilities likely belong in a more common package @@ -24,7 +24,7 @@ var ( vmStorageLock sync.Mutex ) -func reserveVmMemory(ctx context.Context, data ocp_data.Provider, vm *common.Account, accountType cvm.VirtualAccountType, account *common.Account) (*common.Account, uint16, error) { +func reserveVmMemory(ctx context.Context, data ocp_data.Provider, vm *common.Account, accountType vm.VirtualAccountType, account *common.Account) (*common.Account, uint16, error) { vmMemoryLock.Lock() defer vmMemoryLock.Unlock() diff --git a/ocp/worker/swap/util.go b/ocp/worker/swap/util.go index 8bdd8ba..800e71c 100644 --- a/ocp/worker/swap/util.go +++ b/ocp/worker/swap/util.go @@ -19,12 +19,12 @@ import ( "github.com/code-payments/ocp-server/ocp/data/swap" "github.com/code-payments/ocp-server/ocp/data/transaction" transaction_util "github.com/code-payments/ocp-server/ocp/transaction" - "github.com/code-payments/ocp-server/ocp/vm" + vm_util "github.com/code-payments/ocp-server/ocp/vm" "github.com/code-payments/ocp-server/solana" compute_budget "github.com/code-payments/ocp-server/solana/computebudget" - "github.com/code-payments/ocp-server/solana/cvm" "github.com/code-payments/ocp-server/solana/memo" "github.com/code-payments/ocp-server/solana/system" + "github.com/code-payments/ocp-server/solana/vm" ) func (p *runtime) validateSwapState(record *swap.Record, states ...swap.State) error { @@ -372,7 +372,7 @@ func (p *runtime) makeCancellationTransaction(ctx context.Context, record *swap. return nil, err } - memoryAccount, memoryIndex, err := vm.GetVirtualTimelockAccountLocationInMemory(ctx, p.vmIndexerClient, sourceVmConfig.Vm, owner) + memoryAccount, memoryIndex, err := vm_util.GetVirtualTimelockAccountLocationInMemory(ctx, p.vmIndexerClient, sourceVmConfig.Vm, owner) if err != nil { return nil, err } @@ -383,8 +383,8 @@ func (p *runtime) makeCancellationTransaction(ctx context.Context, record *swap. compute_budget.SetComputeUnitLimit(200_000), // todo: optimize this compute_budget.SetComputeUnitPrice(1_000), memo.Instruction("cancel_swap_v0"), - cvm.NewCancelSwapInstruction( - &cvm.CancelSwapInstructionAccounts{ + vm.NewCancelSwapInstruction( + &vm.CancelSwapInstructionAccounts{ VmAuthority: sourceVmConfig.Authority.PublicKey().ToBytes(), Vm: sourceVmConfig.Vm.PublicKey().ToBytes(), VmMemory: memoryAccount.PublicKey().ToBytes(), @@ -393,14 +393,14 @@ func (p *runtime) makeCancellationTransaction(ctx context.Context, record *swap. SwapAta: sourceOwnerVmSwapPdaAccounts.Ata.PublicKey().ToBytes(), VmOmnibus: sourceVmConfig.Omnibus.PublicKey().ToBytes(), }, - &cvm.CancelSwapInstructionArgs{ + &vm.CancelSwapInstructionArgs{ AccountIndex: memoryIndex, Amount: record.Amount, Bump: sourceOwnerVmSwapPdaAccounts.PdaBump, }, ), - cvm.NewCloseSwapAccountIfEmptyInstruction( - &cvm.CloseSwapAccountIfEmptyInstructionAccounts{ + vm.NewCloseSwapAccountIfEmptyInstruction( + &vm.CloseSwapAccountIfEmptyInstructionAccounts{ VmAuthority: sourceVmConfig.Authority.PublicKey().ToBytes(), Vm: sourceVmConfig.Vm.PublicKey().ToBytes(), Swapper: owner.PublicKey().ToBytes(), @@ -408,7 +408,7 @@ func (p *runtime) makeCancellationTransaction(ctx context.Context, record *swap. SwapAta: sourceOwnerVmSwapPdaAccounts.Ata.PublicKey().ToBytes(), Destination: common.GetSubsidizer().PublicKey().ToBytes(), }, - &cvm.CloseSwapAccountIfEmptyInstructionArgs{ + &vm.CloseSwapAccountIfEmptyInstructionArgs{ Bump: sourceOwnerVmSwapPdaAccounts.PdaBump, }, ), diff --git a/solana/currencycreator/instructions_buy_and_deposit_into_vm.go b/solana/currencycreator/instructions_buy_and_deposit_into_vm.go index 53abf6a..ade94e3 100644 --- a/solana/currencycreator/instructions_buy_and_deposit_into_vm.go +++ b/solana/currencycreator/instructions_buy_and_deposit_into_vm.go @@ -4,7 +4,7 @@ import ( "crypto/ed25519" "github.com/code-payments/ocp-server/solana" - "github.com/code-payments/ocp-server/solana/cvm" + "github.com/code-payments/ocp-server/solana/vm" ) const ( @@ -143,7 +143,7 @@ func NewBuyAndDepositIntoVmInstruction( IsSigner: false, }, { - PublicKey: cvm.PROGRAM_ID, + PublicKey: vm.PROGRAM_ID, IsWritable: false, IsSigner: false, }, diff --git a/solana/currencycreator/instructions_sell_and_deposit_into_vm.go b/solana/currencycreator/instructions_sell_and_deposit_into_vm.go index b0e10af..931a219 100644 --- a/solana/currencycreator/instructions_sell_and_deposit_into_vm.go +++ b/solana/currencycreator/instructions_sell_and_deposit_into_vm.go @@ -4,7 +4,7 @@ import ( "crypto/ed25519" "github.com/code-payments/ocp-server/solana" - "github.com/code-payments/ocp-server/solana/cvm" + "github.com/code-payments/ocp-server/solana/vm" ) const ( @@ -143,7 +143,7 @@ func NewSellAndDepositIntoVmInstruction( IsSigner: false, }, { - PublicKey: cvm.PROGRAM_ID, + PublicKey: vm.PROGRAM_ID, IsWritable: false, IsSigner: false, }, diff --git a/solana/cvm/accounts_code_vm.go b/solana/vm/accounts_code_vm.go similarity index 99% rename from solana/cvm/accounts_code_vm.go rename to solana/vm/accounts_code_vm.go index 2a8e4d1..a261edd 100644 --- a/solana/cvm/accounts_code_vm.go +++ b/solana/vm/accounts_code_vm.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "bytes" diff --git a/solana/cvm/accounts_memory_account.go b/solana/vm/accounts_memory_account.go similarity index 99% rename from solana/cvm/accounts_memory_account.go rename to solana/vm/accounts_memory_account.go index f000e66..5ab7a6e 100644 --- a/solana/cvm/accounts_memory_account.go +++ b/solana/vm/accounts_memory_account.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "bytes" diff --git a/solana/cvm/accounts_relay.go b/solana/vm/accounts_relay.go similarity index 99% rename from solana/cvm/accounts_relay.go rename to solana/vm/accounts_relay.go index de650f6..7cf2674 100644 --- a/solana/cvm/accounts_relay.go +++ b/solana/vm/accounts_relay.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "bytes" diff --git a/solana/cvm/accounts_storage.go b/solana/vm/accounts_storage.go similarity index 90% rename from solana/cvm/accounts_storage.go rename to solana/vm/accounts_storage.go index 3f62d38..cb0e7c8 100644 --- a/solana/cvm/accounts_storage.go +++ b/solana/vm/accounts_storage.go @@ -1,4 +1,4 @@ -package cvm +package vm const ( DefaultCompressedStateDepth = 20 diff --git a/solana/cvm/accounts_unlock_state.go b/solana/vm/accounts_unlock_state.go similarity index 99% rename from solana/cvm/accounts_unlock_state.go rename to solana/vm/accounts_unlock_state.go index ea547b9..87ee302 100644 --- a/solana/cvm/accounts_unlock_state.go +++ b/solana/vm/accounts_unlock_state.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "bytes" diff --git a/solana/cvm/address.go b/solana/vm/address.go similarity index 99% rename from solana/cvm/address.go rename to solana/vm/address.go index 78655f9..4999237 100644 --- a/solana/cvm/address.go +++ b/solana/vm/address.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/instructions_cancel_swap.go b/solana/vm/instructions_cancel_swap.go similarity index 99% rename from solana/cvm/instructions_cancel_swap.go rename to solana/vm/instructions_cancel_swap.go index 13b3af0..a165b23 100644 --- a/solana/cvm/instructions_cancel_swap.go +++ b/solana/vm/instructions_cancel_swap.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/instructions_close_swap_account_if_empty.go b/solana/vm/instructions_close_swap_account_if_empty.go similarity index 99% rename from solana/cvm/instructions_close_swap_account_if_empty.go rename to solana/vm/instructions_close_swap_account_if_empty.go index 540c5ba..5f61d39 100644 --- a/solana/cvm/instructions_close_swap_account_if_empty.go +++ b/solana/vm/instructions_close_swap_account_if_empty.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/instructions_compress.go b/solana/vm/instructions_compress.go similarity index 99% rename from solana/cvm/instructions_compress.go rename to solana/vm/instructions_compress.go index 3e871f3..9e636ef 100644 --- a/solana/cvm/instructions_compress.go +++ b/solana/vm/instructions_compress.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/instructions_decompress.go b/solana/vm/instructions_decompress.go similarity index 99% rename from solana/cvm/instructions_decompress.go rename to solana/vm/instructions_decompress.go index c4a5ddd..86fe3d2 100644 --- a/solana/cvm/instructions_decompress.go +++ b/solana/vm/instructions_decompress.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/instructions_exec.go b/solana/vm/instructions_exec.go similarity index 99% rename from solana/cvm/instructions_exec.go rename to solana/vm/instructions_exec.go index 5bfc14d..0ba53fa 100644 --- a/solana/cvm/instructions_exec.go +++ b/solana/vm/instructions_exec.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/instructions_init_memory.go b/solana/vm/instructions_init_memory.go similarity index 99% rename from solana/cvm/instructions_init_memory.go rename to solana/vm/instructions_init_memory.go index fb1eed3..1a3d213 100644 --- a/solana/cvm/instructions_init_memory.go +++ b/solana/vm/instructions_init_memory.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/instructions_init_nonce.go b/solana/vm/instructions_init_nonce.go similarity index 99% rename from solana/cvm/instructions_init_nonce.go rename to solana/vm/instructions_init_nonce.go index 92ef66d..68309a4 100644 --- a/solana/cvm/instructions_init_nonce.go +++ b/solana/vm/instructions_init_nonce.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/instructions_init_relay.go b/solana/vm/instructions_init_relay.go similarity index 99% rename from solana/cvm/instructions_init_relay.go rename to solana/vm/instructions_init_relay.go index 63f331d..cf1e7cb 100644 --- a/solana/cvm/instructions_init_relay.go +++ b/solana/vm/instructions_init_relay.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/instructions_init_storage.go b/solana/vm/instructions_init_storage.go similarity index 99% rename from solana/cvm/instructions_init_storage.go rename to solana/vm/instructions_init_storage.go index 337d709..459fbaa 100644 --- a/solana/cvm/instructions_init_storage.go +++ b/solana/vm/instructions_init_storage.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/instructions_init_timelock.go b/solana/vm/instructions_init_timelock.go similarity index 99% rename from solana/cvm/instructions_init_timelock.go rename to solana/vm/instructions_init_timelock.go index 0521ca9..81d603c 100644 --- a/solana/cvm/instructions_init_timelock.go +++ b/solana/vm/instructions_init_timelock.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/instructions_init_unlock.go b/solana/vm/instructions_init_unlock.go similarity index 99% rename from solana/cvm/instructions_init_unlock.go rename to solana/vm/instructions_init_unlock.go index 1b6b112..c1f6608 100644 --- a/solana/cvm/instructions_init_unlock.go +++ b/solana/vm/instructions_init_unlock.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/instructions_init_vm.go b/solana/vm/instructions_init_vm.go similarity index 99% rename from solana/cvm/instructions_init_vm.go rename to solana/vm/instructions_init_vm.go index 7eeeeec..91dd4f4 100644 --- a/solana/cvm/instructions_init_vm.go +++ b/solana/vm/instructions_init_vm.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/instructions_resize_memory.go b/solana/vm/instructions_resize_memory.go similarity index 99% rename from solana/cvm/instructions_resize_memory.go rename to solana/vm/instructions_resize_memory.go index 95c7c91..63c6923 100644 --- a/solana/cvm/instructions_resize_memory.go +++ b/solana/vm/instructions_resize_memory.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/instructions_snapshot.go b/solana/vm/instructions_snapshot.go similarity index 98% rename from solana/cvm/instructions_snapshot.go rename to solana/vm/instructions_snapshot.go index 60c6a4c..da1ec06 100644 --- a/solana/cvm/instructions_snapshot.go +++ b/solana/vm/instructions_snapshot.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/instructions_timelock_deposit_from_pda.go b/solana/vm/instructions_timelock_deposit_from_pda.go similarity index 99% rename from solana/cvm/instructions_timelock_deposit_from_pda.go rename to solana/vm/instructions_timelock_deposit_from_pda.go index b1f7130..b5b153f 100644 --- a/solana/cvm/instructions_timelock_deposit_from_pda.go +++ b/solana/vm/instructions_timelock_deposit_from_pda.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/instructions_transfer_for_swap.go b/solana/vm/instructions_transfer_for_swap.go similarity index 99% rename from solana/cvm/instructions_transfer_for_swap.go rename to solana/vm/instructions_transfer_for_swap.go index ee144ff..fece9aa 100644 --- a/solana/cvm/instructions_transfer_for_swap.go +++ b/solana/vm/instructions_transfer_for_swap.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/program.go b/solana/vm/program.go similarity index 98% rename from solana/cvm/program.go rename to solana/vm/program.go index 2cc2f71..df49b0e 100644 --- a/solana/cvm/program.go +++ b/solana/vm/program.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/transaction.go b/solana/vm/transaction.go similarity index 93% rename from solana/cvm/transaction.go rename to solana/vm/transaction.go index c031ab8..20a3d8c 100644 --- a/solana/cvm/transaction.go +++ b/solana/vm/transaction.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/types_account_type.go b/solana/vm/types_account_type.go similarity index 94% rename from solana/cvm/types_account_type.go rename to solana/vm/types_account_type.go index fb65681..bb76939 100644 --- a/solana/cvm/types_account_type.go +++ b/solana/vm/types_account_type.go @@ -1,4 +1,4 @@ -package cvm +package vm type AccountType uint8 diff --git a/solana/cvm/types_code_instruction.go b/solana/vm/types_code_instruction.go similarity index 98% rename from solana/cvm/types_code_instruction.go rename to solana/vm/types_code_instruction.go index b7f31f6..1297e58 100644 --- a/solana/cvm/types_code_instruction.go +++ b/solana/vm/types_code_instruction.go @@ -1,4 +1,4 @@ -package cvm +package vm type CodeInstruction uint8 diff --git a/solana/cvm/types_hash.go b/solana/vm/types_hash.go similarity index 98% rename from solana/cvm/types_hash.go rename to solana/vm/types_hash.go index 1bafe7a..4e87f2e 100644 --- a/solana/cvm/types_hash.go +++ b/solana/vm/types_hash.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "encoding/binary" diff --git a/solana/cvm/types_item_state.go b/solana/vm/types_item_state.go similarity index 98% rename from solana/cvm/types_item_state.go rename to solana/vm/types_item_state.go index 7b98485..f6f3615 100644 --- a/solana/cvm/types_item_state.go +++ b/solana/vm/types_item_state.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "fmt" diff --git a/solana/cvm/types_memory_allocator.go b/solana/vm/types_memory_allocator.go similarity index 92% rename from solana/cvm/types_memory_allocator.go rename to solana/vm/types_memory_allocator.go index 47f7f9b..f6ada7c 100644 --- a/solana/cvm/types_memory_allocator.go +++ b/solana/vm/types_memory_allocator.go @@ -1,4 +1,4 @@ -package cvm +package vm const ( MemoryV0NumAccounts = 32_000 diff --git a/solana/cvm/types_memory_layout.go b/solana/vm/types_memory_layout.go similarity index 98% rename from solana/cvm/types_memory_layout.go rename to solana/vm/types_memory_layout.go index 4e070bc..0b8581f 100644 --- a/solana/cvm/types_memory_layout.go +++ b/solana/vm/types_memory_layout.go @@ -1,4 +1,4 @@ -package cvm +package vm type MemoryLayout uint8 diff --git a/solana/cvm/types_memory_version.go b/solana/vm/types_memory_version.go similarity index 96% rename from solana/cvm/types_memory_version.go rename to solana/vm/types_memory_version.go index 381e354..3768a5a 100644 --- a/solana/cvm/types_memory_version.go +++ b/solana/vm/types_memory_version.go @@ -1,4 +1,4 @@ -package cvm +package vm type MemoryVersion uint8 diff --git a/solana/cvm/types_merkle_tree.go b/solana/vm/types_merkle_tree.go similarity index 98% rename from solana/cvm/types_merkle_tree.go rename to solana/vm/types_merkle_tree.go index 7f51e1b..7488f7a 100644 --- a/solana/cvm/types_merkle_tree.go +++ b/solana/vm/types_merkle_tree.go @@ -1,4 +1,4 @@ -package cvm +package vm import "fmt" diff --git a/solana/cvm/types_message.go b/solana/vm/types_message.go similarity index 99% rename from solana/cvm/types_message.go rename to solana/vm/types_message.go index eef0f19..d2b6893 100644 --- a/solana/cvm/types_message.go +++ b/solana/vm/types_message.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/types_opcode.go b/solana/vm/types_opcode.go similarity index 97% rename from solana/cvm/types_opcode.go rename to solana/vm/types_opcode.go index 93b0afa..ba7c45a 100644 --- a/solana/cvm/types_opcode.go +++ b/solana/vm/types_opcode.go @@ -1,4 +1,4 @@ -package cvm +package vm type Opcode uint8 diff --git a/solana/cvm/types_recent_roots.go b/solana/vm/types_recent_roots.go similarity index 98% rename from solana/cvm/types_recent_roots.go rename to solana/vm/types_recent_roots.go index a73553f..96c9a57 100644 --- a/solana/cvm/types_recent_roots.go +++ b/solana/vm/types_recent_roots.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "fmt" diff --git a/solana/cvm/types_signature.go b/solana/vm/types_signature.go similarity index 97% rename from solana/cvm/types_signature.go rename to solana/vm/types_signature.go index d918e48..19cd488 100644 --- a/solana/cvm/types_signature.go +++ b/solana/vm/types_signature.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "github.com/mr-tron/base58" diff --git a/solana/cvm/types_slice_allocator.go b/solana/vm/types_slice_allocator.go similarity index 99% rename from solana/cvm/types_slice_allocator.go rename to solana/vm/types_slice_allocator.go index 142f110..c354b2b 100644 --- a/solana/cvm/types_slice_allocator.go +++ b/solana/vm/types_slice_allocator.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "fmt" diff --git a/solana/cvm/types_timelock_state.go b/solana/vm/types_timelock_state.go similarity index 97% rename from solana/cvm/types_timelock_state.go rename to solana/vm/types_timelock_state.go index cef8efe..f294041 100644 --- a/solana/cvm/types_timelock_state.go +++ b/solana/vm/types_timelock_state.go @@ -1,4 +1,4 @@ -package cvm +package vm type TimelockState uint8 diff --git a/solana/cvm/types_token_pool.go b/solana/vm/types_token_pool.go similarity index 98% rename from solana/cvm/types_token_pool.go rename to solana/vm/types_token_pool.go index ec850c7..55c8097 100644 --- a/solana/cvm/types_token_pool.go +++ b/solana/vm/types_token_pool.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/types_virtual_account_type.go b/solana/vm/types_virtual_account_type.go similarity index 97% rename from solana/cvm/types_virtual_account_type.go rename to solana/vm/types_virtual_account_type.go index 9bee24d..b50c11c 100644 --- a/solana/cvm/types_virtual_account_type.go +++ b/solana/vm/types_virtual_account_type.go @@ -1,4 +1,4 @@ -package cvm +package vm import "errors" diff --git a/solana/cvm/utils.go b/solana/vm/utils.go similarity index 99% rename from solana/cvm/utils.go rename to solana/vm/utils.go index 83caa86..447910e 100644 --- a/solana/cvm/utils.go +++ b/solana/vm/utils.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/virtual_accounts.go b/solana/vm/virtual_accounts.go similarity index 97% rename from solana/cvm/virtual_accounts.go rename to solana/vm/virtual_accounts.go index 67e7f1e..a7a97b8 100644 --- a/solana/cvm/virtual_accounts.go +++ b/solana/vm/virtual_accounts.go @@ -1,4 +1,4 @@ -package cvm +package vm func GetVirtualAccountSize(accountType VirtualAccountType) uint32 { switch accountType { diff --git a/solana/cvm/virtual_accounts_durable_nonce.go b/solana/vm/virtual_accounts_durable_nonce.go similarity index 98% rename from solana/cvm/virtual_accounts_durable_nonce.go rename to solana/vm/virtual_accounts_durable_nonce.go index e10505d..eb159c1 100644 --- a/solana/cvm/virtual_accounts_durable_nonce.go +++ b/solana/vm/virtual_accounts_durable_nonce.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/virtual_accounts_relay_account.go b/solana/vm/virtual_accounts_relay_account.go similarity index 98% rename from solana/cvm/virtual_accounts_relay_account.go rename to solana/vm/virtual_accounts_relay_account.go index 281fd7e..60c39db 100644 --- a/solana/cvm/virtual_accounts_relay_account.go +++ b/solana/vm/virtual_accounts_relay_account.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/virtual_accounts_timelock_account.go b/solana/vm/virtual_accounts_timelock_account.go similarity index 99% rename from solana/cvm/virtual_accounts_timelock_account.go rename to solana/vm/virtual_accounts_timelock_account.go index dae46f6..da75581 100644 --- a/solana/cvm/virtual_accounts_timelock_account.go +++ b/solana/vm/virtual_accounts_timelock_account.go @@ -1,4 +1,4 @@ -package cvm +package vm import ( "crypto/ed25519" diff --git a/solana/cvm/virtual_instructions.go b/solana/vm/virtual_instructions.go similarity index 84% rename from solana/cvm/virtual_instructions.go rename to solana/vm/virtual_instructions.go index 0c5c303..cac6bc1 100644 --- a/solana/cvm/virtual_instructions.go +++ b/solana/vm/virtual_instructions.go @@ -1,4 +1,4 @@ -package cvm +package vm type VirtualInstruction struct { Opcode Opcode diff --git a/solana/cvm/virtual_instructions_airdrop.go b/solana/vm/virtual_instructions_airdrop.go similarity index 97% rename from solana/cvm/virtual_instructions_airdrop.go rename to solana/vm/virtual_instructions_airdrop.go index e6d0b6a..6ec7fad 100644 --- a/solana/cvm/virtual_instructions_airdrop.go +++ b/solana/vm/virtual_instructions_airdrop.go @@ -1,4 +1,4 @@ -package cvm +package vm const ( AirdropVirtrualInstructionDataSize = (SignatureSize + // signature diff --git a/solana/cvm/virtual_instructions_conditional_transfer.go b/solana/vm/virtual_instructions_conditional_transfer.go similarity index 97% rename from solana/cvm/virtual_instructions_conditional_transfer.go rename to solana/vm/virtual_instructions_conditional_transfer.go index e7f47e8..4be8c65 100644 --- a/solana/cvm/virtual_instructions_conditional_transfer.go +++ b/solana/vm/virtual_instructions_conditional_transfer.go @@ -1,4 +1,4 @@ -package cvm +package vm const ( ConditionalTransferVirtrualInstructionDataSize = (SignatureSize + // signature diff --git a/solana/cvm/virtual_instructions_external_relay.go b/solana/vm/virtual_instructions_external_relay.go similarity index 98% rename from solana/cvm/virtual_instructions_external_relay.go rename to solana/vm/virtual_instructions_external_relay.go index 07d0d38..1cb4945 100644 --- a/solana/cvm/virtual_instructions_external_relay.go +++ b/solana/vm/virtual_instructions_external_relay.go @@ -1,4 +1,4 @@ -package cvm +package vm const ( ExternalRelayVirtrualInstructionDataSize = (8 + // amount diff --git a/solana/cvm/virtual_instructions_external_transfer.go b/solana/vm/virtual_instructions_external_transfer.go similarity index 97% rename from solana/cvm/virtual_instructions_external_transfer.go rename to solana/vm/virtual_instructions_external_transfer.go index 29cd572..49684a9 100644 --- a/solana/cvm/virtual_instructions_external_transfer.go +++ b/solana/vm/virtual_instructions_external_transfer.go @@ -1,4 +1,4 @@ -package cvm +package vm const ( ExternalTransferVirtrualInstructionDataSize = (SignatureSize + // signature diff --git a/solana/cvm/virtual_instructions_external_withdraw.go b/solana/vm/virtual_instructions_external_withdraw.go similarity index 97% rename from solana/cvm/virtual_instructions_external_withdraw.go rename to solana/vm/virtual_instructions_external_withdraw.go index 5a4b98a..29133b4 100644 --- a/solana/cvm/virtual_instructions_external_withdraw.go +++ b/solana/vm/virtual_instructions_external_withdraw.go @@ -1,4 +1,4 @@ -package cvm +package vm const ( ExternalWithdrawVirtrualInstructionDataSize = SignatureSize // signature diff --git a/solana/cvm/virtual_instructions_relay.go b/solana/vm/virtual_instructions_relay.go similarity index 98% rename from solana/cvm/virtual_instructions_relay.go rename to solana/vm/virtual_instructions_relay.go index 237ca03..a0a4550 100644 --- a/solana/cvm/virtual_instructions_relay.go +++ b/solana/vm/virtual_instructions_relay.go @@ -1,4 +1,4 @@ -package cvm +package vm const ( RelayVirtrualInstructionDataSize = (8 + // amount diff --git a/solana/cvm/virtual_instructions_transfer.go b/solana/vm/virtual_instructions_transfer.go similarity index 97% rename from solana/cvm/virtual_instructions_transfer.go rename to solana/vm/virtual_instructions_transfer.go index 8e3d620..efd65e0 100644 --- a/solana/cvm/virtual_instructions_transfer.go +++ b/solana/vm/virtual_instructions_transfer.go @@ -1,4 +1,4 @@ -package cvm +package vm const ( TransferVirtrualInstructionDataSize = (SignatureSize + // signature diff --git a/solana/cvm/virtual_instructions_withdraw.go b/solana/vm/virtual_instructions_withdraw.go similarity index 97% rename from solana/cvm/virtual_instructions_withdraw.go rename to solana/vm/virtual_instructions_withdraw.go index dda3356..92ffd03 100644 --- a/solana/cvm/virtual_instructions_withdraw.go +++ b/solana/vm/virtual_instructions_withdraw.go @@ -1,4 +1,4 @@ -package cvm +package vm const ( WithdrawVirtrualInstructionDataSize = SignatureSize // signature