Skip to content

Commit

Permalink
solana: next_transceiver_id to be 128 max
Browse files Browse the repository at this point in the history
Signed-off-by: bingyuyap <[email protected]>
  • Loading branch information
bingyuyap committed Oct 2, 2024
1 parent a686731 commit 2097b45
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
1 change: 0 additions & 1 deletion svm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ codegen-units = 1
opt-level = 3
incremental = false
codegen-units = 1

12 changes: 4 additions & 8 deletions svm/programs/router/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ classDiagram
bump: u8
integrator_id: u64
chain_id: u16
next_in_transceiver_id: u64
next_out_transceiver_id: u64
next_in_transceiver_id: u8
next_out_transceiver_id: u8
in_transceiver_bitmap: Bitmap
out_transceiver_bitmap: Bitmap
}
class RegisteredTransceiver {
bump: u8
integrator_id: u64
id: u64
id: u8
chain_id: u16
address: Pubkey
}
Expand Down Expand Up @@ -67,11 +67,7 @@ classDiagram
- Associated with a specific integrator and chain.
- Has a unique ID within its integrator and chain context.

5. **TransceiverType**: Enum to distinguish between incoming and outgoing transceivers.

- Allows for different handling of inbound and outbound messages.

6. **Bitmap**: Utility struct for efficient storage and manipulation of boolean flags.
5. **Bitmap**: Utility struct for efficient storage and manipulation of boolean flags.
- Used to track the status of transceivers (active/inactive).

### Relationships
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn register_transceiver(
};

// Ensure we don't exceed the maximum number of transceivers
if transceiver_id >= IntegratorChainTransceivers::MAX_TRANSCEIVERS as u64 {
if transceiver_id >= IntegratorChainTransceivers::MAX_TRANSCEIVERS as u8 {
return Err(RouterError::MaxTransceiversReached.into());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ pub struct IntegratorChainTransceivers {
pub chain_id: u16,

/// Counter for assigning IDs to incoming transceivers
pub next_in_transceiver_id: u64,
pub next_in_transceiver_id: u8,

/// Counter for assigning IDs to outgoing transceivers
pub next_out_transceiver_id: u64,
pub next_out_transceiver_id: u8,

/// Bitmap tracking the status of incoming transceivers
pub in_transceiver_bitmap: Bitmap,
Expand All @@ -36,7 +36,7 @@ impl IntegratorChainTransceivers {
pub const SEED_PREFIX: &'static [u8] = b"integrator_chain_transceivers";

/// Maximum number of transceivers allowed per direction (in/out)
pub const MAX_TRANSCEIVERS: usize = 64;
pub const MAX_TRANSCEIVERS: u8 = 128;

pub fn set_in_transceiver(&mut self, index: u8, value: bool) -> Result<()> {
self.in_transceiver_bitmap
Expand Down
2 changes: 1 addition & 1 deletion svm/programs/router/src/state/registered_transceiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct RegisteredTransceiver {
pub integrator_id: u64,

/// Unique identifier for the transceiver within its integrator and chain context
pub id: u64,
pub id: u8,

/// Identifier for the blockchain this transceiver operates on
pub chain_id: u16,
Expand Down
3 changes: 2 additions & 1 deletion svm/programs/router/tests/register_transceiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async fn test_register_transceiver_success() {
RegisteredTransceiver::SEED_PREFIX,
integrator.id.to_le_bytes().as_ref(),
chain_id.to_le_bytes().as_ref(),
0u64.to_le_bytes().as_ref(),
0u8.to_le_bytes().as_ref(),
],
&router::id(),
);
Expand Down Expand Up @@ -109,6 +109,7 @@ async fn test_register_transceiver_success() {
integrator_chain_transceivers.in_transceiver_bitmap,
expected_bitmap
);

// Verify the RegisteredTransceiver account
let registered_transceiver: RegisteredTransceiver =
get_account(&mut context.banks_client, registered_transceiver_pda).await;
Expand Down

0 comments on commit 2097b45

Please sign in to comment.