Skip to content

Commit

Permalink
Rename EngineState::to_bytes -> EngineState::borsh_serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
birchmd committed May 10, 2023
1 parent 0c4e62d commit b1015b0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 3 additions & 1 deletion engine-tests/src/tests/repro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ fn repro_common(context: &ReproContext) {
let tx_bytes = hex::decode(tx_hex.trim()).unwrap();

// Make a random call that touches the Engine state to force the lazy migration
runner.call("get_chain_id", "relay.aurora", Vec::new()).unwrap();
runner
.call("get_chain_id", "relay.aurora", Vec::new())
.unwrap();
// Run benchmark post-migration
let outcome = runner.call("submit", "relay.aurora", tx_bytes).unwrap();
let profile = ExecutionProfile::new(&outcome);
Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/tests/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fn test_state_format() {
"0300000000000000",
]
.concat();
assert_eq!(hex::encode(state.to_bytes().unwrap()), expected_hex);
assert_eq!(hex::encode(state.borsh_serialize().unwrap()), expected_hex);
}

fn generate_code(len: usize) -> Vec<u8> {
Expand Down
8 changes: 3 additions & 5 deletions engine/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct EngineState {
}

impl EngineState {
pub fn to_bytes(&self) -> Result<Vec<u8>, error::EngineStateError> {
pub fn borsh_serialize(&self) -> Result<Vec<u8>, error::EngineStateError> {
let borshable: BorshableEngineState = self.into();
borshable
.try_to_vec()
Expand All @@ -36,9 +36,7 @@ impl EngineState {
bytes: &[u8],
io: &I,
) -> Result<Self, error::EngineStateError> {
let borshable = if let Ok(s) = BorshableEngineState::try_from_slice(bytes) {
s
} else {
let Ok(borshable) = BorshableEngineState::try_from_slice(bytes) else {
let legacy = BorshableEngineStateV1::try_from_slice(bytes)
.map_err(|_| EngineStateError::DeserializationFailed)?;
let result = legacy.into();
Expand Down Expand Up @@ -154,7 +152,7 @@ pub fn get_state<I: IO + Copy>(io: &I) -> Result<EngineState, error::EngineState
pub fn set_state<I: IO>(io: &mut I, state: &EngineState) -> Result<(), EngineStateError> {
io.write_storage(
&bytes_to_key(KeyPrefix::Config, STATE_KEY),
&state.to_bytes()?,
&state.borsh_serialize()?,
);

Ok(())
Expand Down

0 comments on commit b1015b0

Please sign in to comment.