Skip to content

Commit

Permalink
Merge #996: Box value encoded in a variant to reduce enum stack space
Browse files Browse the repository at this point in the history
9906cea Box value encoded in a variant to reduce enum stack space (Riccardo Casatta)

Pull request description:

  before

  ```
  print-type-size type: `util::psbt::error::Error`: 120 bytes, alignment: 8 bytes
  print-type-size     discriminant: 1 bytes
  print-type-size     variant `CombineInconsistentKeySources`: 115 bytes
  print-type-size         padding: 3 bytes
  print-type-size         field `.0`: 112 bytes, alignment: 4 bytes
  print-type-size     variant `InvalidKey`: 39 bytes
  print-type-size         padding: 7 bytes
  print-type-size         field `.0`: 32 bytes, alignment: 8 bytes
  ```

  after
  ```
  print-type-size type: `util::psbt::error::Error`: 40 bytes, alignment: 8 bytes
  print-type-size     discriminant: 1 bytes
  print-type-size     variant `InvalidKey`: 39 bytes
  print-type-size         padding: 7 bytes
  print-type-size         field `.0`: 32 bytes, alignment: 8 bytes
  print-type-size     variant `DuplicateKey`: 39 bytes
  print-type-size         padding: 7 bytes
  print-type-size         field `.0`: 32 bytes, alignment: 8 bytes
  ```

  `util::psbt::error::Error` is wrapped also in `consensus::encode::Error` and stack savings are gained there also

ACKs for top commit:
  apoelstra:
    ACK 9906cea
  tcharding:
    ACK 9906cea
  sanket1729:
    utACK 9906cea

Tree-SHA512: e03988fcbc3dd87f83d00dd84ec1c538bc5c63bea97ff4a69a715621f498f57d7fe2a623e351942d9532af40c723e42a9eb6ef48ebf4c62ddf5c0f44e9ea0a07
  • Loading branch information
sanket1729 committed May 20, 2022
2 parents fcb035f + 9906cea commit 2b1154c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/util/psbt/error.rs
Expand Up @@ -80,7 +80,7 @@ pub enum Error {
},
/// Conflicting data during combine procedure:
/// global extended public key has inconsistent key sources
CombineInconsistentKeySources(ExtendedPubKey),
CombineInconsistentKeySources(Box<ExtendedPubKey>),
/// Serialization error in bitcoin consensus-encoded structures
ConsensusEncoding,
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/psbt/mod.rs
Expand Up @@ -192,7 +192,7 @@ impl PartiallySignedTransaction {
entry.insert((fingerprint1, derivation1));
continue
}
return Err(Error::CombineInconsistentKeySources(xpub));
return Err(Error::CombineInconsistentKeySources(Box::new(xpub)));
}
}
}
Expand Down

0 comments on commit 2b1154c

Please sign in to comment.