fix(bonding-curve): tolerate extra trailing bytes in account data
BondingCurveAccount::try_from_slice requires the entire input slice to be consumed, which fails with "Not all bytes read" when the on-chain bonding curve account has been extended with new fields (e.g. after a protocol upgrade). Switch to BorshDeserialize::deserialize which reads the known fields and silently ignores any trailing bytes.
This commit is contained in:
@@ -545,7 +545,11 @@ pub async fn fetch_bonding_curve_account(
|
|||||||
return Err(anyhow!("Bonding curve not found"));
|
return Err(anyhow!("Bonding curve not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut bonding_curve = BondingCurveAccount::try_from_slice(&account.data[8..])
|
// Use `deserialize` instead of `try_from_slice` so that extra trailing bytes
|
||||||
|
// (from on-chain schema additions like new fields) are silently ignored.
|
||||||
|
// `try_from_slice` requires the entire slice to be consumed, causing
|
||||||
|
// "Not all bytes read" when the account has been extended.
|
||||||
|
let mut bonding_curve = BondingCurveAccount::deserialize(&mut &account.data[8..])
|
||||||
.map_err(|e| anyhow::anyhow!("Failed to decode bonding curve account: {}", e))?;
|
.map_err(|e| anyhow::anyhow!("Failed to decode bonding curve account: {}", e))?;
|
||||||
bonding_curve.account = bonding_curve_pda;
|
bonding_curve.account = bonding_curve_pda;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user