program: sequence check as u8 (#909)

* program: sequence check as u8 (reuse existing padding)
This commit is contained in:
Serge Farny 2024-03-11 10:45:53 +01:00 committed by GitHub
parent 494835631b
commit 0728bb566f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 36 additions and 99 deletions

View File

@ -1786,7 +1786,7 @@
"args": [
{
"name": "expectedSequenceNumber",
"type": "u64"
"type": "u8"
}
]
},
@ -7901,13 +7901,8 @@
"type": "u8"
},
{
"name": "padding",
"type": {
"array": [
"u8",
1
]
}
"name": "sequenceNumber",
"type": "u8"
},
{
"name": "netDeposits",
@ -7972,16 +7967,12 @@
],
"type": "u64"
},
{
"name": "sequenceNumber",
"type": "u64"
},
{
"name": "reserved",
"type": {
"array": [
"u8",
144
152
]
}
},
@ -9703,13 +9694,8 @@
"type": "u8"
},
{
"name": "padding",
"type": {
"array": [
"u8",
1
]
}
"name": "sequenceNumber",
"type": "u8"
},
{
"name": "netDeposits",
@ -9755,16 +9741,12 @@
"name": "lastCollateralFeeCharge",
"type": "u64"
},
{
"name": "sequenceNumber",
"type": "u64"
},
{
"name": "reserved",
"type": {
"array": [
"u8",
144
152
]
}
}

View File

@ -4,7 +4,7 @@ use crate::accounts_ix::*;
use crate::error::MangoError;
use crate::state::*;
pub fn sequence_check(ctx: Context<SequenceCheck>, expected_sequence_number: u64) -> Result<()> {
pub fn sequence_check(ctx: Context<SequenceCheck>, expected_sequence_number: u8) -> Result<()> {
let mut account = ctx.accounts.account.load_full_mut()?;
require_eq!(

View File

@ -458,10 +458,7 @@ pub mod mango_v4 {
Ok(())
}
pub fn sequence_check(
ctx: Context<SequenceCheck>,
expected_sequence_number: u64,
) -> Result<()> {
pub fn sequence_check(ctx: Context<SequenceCheck>, expected_sequence_number: u8) -> Result<()> {
#[cfg(feature = "enable-gpl")]
instructions::sequence_check(ctx, expected_sequence_number)?;
Ok(())

View File

@ -123,8 +123,7 @@ pub struct MangoAccount {
pub bump: u8,
#[derivative(Debug = "ignore")]
pub padding: [u8; 1],
pub sequence_number: u8,
// (Display only)
// Cumulative (deposits - withdraws)
@ -157,10 +156,8 @@ pub struct MangoAccount {
/// Time at which the last collateral fee was charged
pub last_collateral_fee_charge: u64,
pub sequence_number: u64,
#[derivative(Debug = "ignore")]
pub reserved: [u8; 144],
pub reserved: [u8; 152],
// dynamic
pub header_version: u8,
@ -202,7 +199,7 @@ impl MangoAccount {
in_health_region: 0,
account_num: 0,
bump: 0,
padding: Default::default(),
sequence_number: 0,
net_deposits: 0,
perp_spot_transfers: 0,
health_region_begin_init_health: 0,
@ -214,8 +211,7 @@ impl MangoAccount {
temporary_delegate: Pubkey::default(),
temporary_delegate_expiry: 0,
last_collateral_fee_charge: 0,
sequence_number: 0,
reserved: [0; 144],
reserved: [0; 152],
header_version: DEFAULT_MANGO_ACCOUNT_VERSION,
padding3: Default::default(),
padding4: Default::default(),
@ -328,7 +324,7 @@ pub struct MangoAccountFixed {
being_liquidated: u8,
in_health_region: u8,
pub bump: u8,
pub padding: [u8; 1],
pub sequence_number: u8,
pub net_deposits: i64,
pub perp_spot_transfers: i64,
pub health_region_begin_init_health: i64,
@ -340,12 +336,11 @@ pub struct MangoAccountFixed {
pub temporary_delegate: Pubkey,
pub temporary_delegate_expiry: u64,
pub last_collateral_fee_charge: u64,
pub sequence_number: u64,
pub reserved: [u8; 144],
pub reserved: [u8; 152],
}
const_assert_eq!(
size_of::<MangoAccountFixed>(),
32 * 4 + 8 + 8 * 8 + 32 + 8 + 8 + 8 + 144
32 * 4 + 8 + 8 * 8 + 32 + 8 + 8 + 152
);
const_assert_eq!(size_of::<MangoAccountFixed>(), 400);
const_assert_eq!(size_of::<MangoAccountFixed>() % 8, 0);
@ -2901,7 +2896,7 @@ mod tests {
being_liquidated: fixed.being_liquidated,
in_health_region: fixed.in_health_region,
bump: fixed.bump,
padding: Default::default(),
sequence_number: 0,
net_deposits: fixed.net_deposits,
perp_spot_transfers: fixed.perp_spot_transfers,
health_region_begin_init_health: fixed.health_region_begin_init_health,
@ -2913,8 +2908,7 @@ mod tests {
temporary_delegate: fixed.temporary_delegate,
temporary_delegate_expiry: fixed.temporary_delegate_expiry,
last_collateral_fee_charge: fixed.last_collateral_fee_charge,
sequence_number: 0,
reserved: [0u8; 144],
reserved: [0u8; 152],
header_version: *zerocopy_reader.header_version(),
padding3: Default::default(),

View File

@ -5174,7 +5174,7 @@ impl<T: ClientInstruction> ClientInstruction for HealthAccountSkipping<T> {
pub struct SequenceCheckInstruction {
pub account: Pubkey,
pub owner: TestKeypair,
pub expected_sequence_number: u64,
pub expected_sequence_number: u8,
}
#[async_trait::async_trait(?Send)]
impl ClientInstruction for SequenceCheckInstruction {

View File

@ -23,7 +23,7 @@ describe('Mango Account', () => {
new BN(0),
new BN(0),
new BN(0),
new BN(0),
0,
0,
[],
[],

View File

@ -44,7 +44,7 @@ export class MangoAccount {
buybackFeesAccruedCurrent: BN;
buybackFeesAccruedPrevious: BN;
buybackFeesExpiryTimestamp: BN;
sequenceNumber: BN;
sequenceNumber: number;
headerVersion: number;
tokens: unknown;
serum3: unknown;
@ -96,7 +96,7 @@ export class MangoAccount {
public buybackFeesAccruedCurrent: BN,
public buybackFeesAccruedPrevious: BN,
public buybackFeesExpiryTimestamp: BN,
public sequenceNumber: BN,
public sequenceNumber: number,
public headerVersion: number,
tokens: TokenPositionDto[],
serum3: Serum3PositionDto[],

View File

@ -1786,7 +1786,7 @@ export type MangoV4 = {
"args": [
{
"name": "expectedSequenceNumber",
"type": "u64"
"type": "u8"
}
]
},
@ -7901,13 +7901,8 @@ export type MangoV4 = {
"type": "u8"
},
{
"name": "padding",
"type": {
"array": [
"u8",
1
]
}
"name": "sequenceNumber",
"type": "u8"
},
{
"name": "netDeposits",
@ -7972,16 +7967,12 @@ export type MangoV4 = {
],
"type": "u64"
},
{
"name": "sequenceNumber",
"type": "u64"
},
{
"name": "reserved",
"type": {
"array": [
"u8",
144
152
]
}
},
@ -9703,13 +9694,8 @@ export type MangoV4 = {
"type": "u8"
},
{
"name": "padding",
"type": {
"array": [
"u8",
1
]
}
"name": "sequenceNumber",
"type": "u8"
},
{
"name": "netDeposits",
@ -9755,16 +9741,12 @@ export type MangoV4 = {
"name": "lastCollateralFeeCharge",
"type": "u64"
},
{
"name": "sequenceNumber",
"type": "u64"
},
{
"name": "reserved",
"type": {
"array": [
"u8",
144
152
]
}
}
@ -16193,7 +16175,7 @@ export const IDL: MangoV4 = {
"args": [
{
"name": "expectedSequenceNumber",
"type": "u64"
"type": "u8"
}
]
},
@ -22308,13 +22290,8 @@ export const IDL: MangoV4 = {
"type": "u8"
},
{
"name": "padding",
"type": {
"array": [
"u8",
1
]
}
"name": "sequenceNumber",
"type": "u8"
},
{
"name": "netDeposits",
@ -22379,16 +22356,12 @@ export const IDL: MangoV4 = {
],
"type": "u64"
},
{
"name": "sequenceNumber",
"type": "u64"
},
{
"name": "reserved",
"type": {
"array": [
"u8",
144
152
]
}
},
@ -24110,13 +24083,8 @@ export const IDL: MangoV4 = {
"type": "u8"
},
{
"name": "padding",
"type": {
"array": [
"u8",
1
]
}
"name": "sequenceNumber",
"type": "u8"
},
{
"name": "netDeposits",
@ -24162,16 +24130,12 @@ export const IDL: MangoV4 = {
"name": "lastCollateralFeeCharge",
"type": "u64"
},
{
"name": "sequenceNumber",
"type": "u64"
},
{
"name": "reserved",
"type": {
"array": [
"u8",
144
152
]
}
}