-
Notifications
You must be signed in to change notification settings - Fork 499
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
xdr and horizon: Optimize compress-marshaling of ledger keys (#4071)
- Loading branch information
Showing
10 changed files
with
190 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,14 @@ | ||
package xdr | ||
|
||
// MarshalBinaryCompress marshals ClaimableBalanceId to []byte but unlike | ||
// MarshalBinary() it removes all unnecessary bytes, exploiting the fact | ||
// that XDR is padding data to 4 bytes in union discriminants etc. | ||
// It's primary use is in ingest/io.StateReader that keep LedgerKeys in | ||
// memory so this function decrease memory requirements. | ||
// | ||
// Warning, do not use UnmarshalBinary() on data encoded using this method! | ||
func (cb ClaimableBalanceId) MarshalBinaryCompress() ([]byte, error) { | ||
m := []byte{byte(cb.Type)} | ||
|
||
func (e *EncodingBuffer) claimableBalanceCompressEncodeTo(cb ClaimableBalanceId) error { | ||
if err := e.xdrEncoderBuf.WriteByte(byte(cb.Type)); err != nil { | ||
return err | ||
} | ||
switch cb.Type { | ||
case ClaimableBalanceIdTypeClaimableBalanceIdTypeV0: | ||
hash, err := cb.V0.MarshalBinary() | ||
if err != nil { | ||
return nil, err | ||
} | ||
m = append(m, hash...) | ||
// TODO fix before Protocol 18 | ||
// case ClaimableBalanceIdTypeClaimableBalanceIdTypeFromPoolRevoke: | ||
_, err := e.xdrEncoderBuf.Write(cb.V0[:]) | ||
return err | ||
default: | ||
panic("Unknown type") | ||
} | ||
|
||
return m, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.