Skip to content

Commit

Permalink
remove compression for round and mint in store
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricfung committed Oct 13, 2023
1 parent f98e434 commit 883f625
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 122 deletions.
2 changes: 0 additions & 2 deletions common/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ func (tx *SignedTransaction) validateDeposit(store DataStore, payloadHash crypto
if sig == nil {
return fmt.Errorf("invalid domain signature index for deposit")
}
// FIXME change this to custodian only when available
// domain key will be used as observer for the safe network
custodian, err := store.ReadCustodian(snapTime)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions common/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ func TestCommonDataEncoding(t *testing.T) {

enc := mint.Marshal()
require.Equal("777700010000000000000000007b000412b9af98eea889c227076f8c62106b59a478e043c0030392f3be0f5d714ed27953cb2668", hex.EncodeToString(enc))
enc = mint.CompressMarshal()
require.Equal("0000000028b52ffd0300c118533ca10100777700010000000000000000007b000412b9af98eea889c227076f8c62106b59a478e043c0030392f3be0f5d714ed27953cb2668", hex.EncodeToString(enc))
res, err := DecompressUnmarshalMintDistribution(enc)
enc = mint.Marshal()
require.Equal("777700010000000000000000007b000412b9af98eea889c227076f8c62106b59a478e043c0030392f3be0f5d714ed27953cb2668", hex.EncodeToString(enc))
res, err := UnmarshalMintDistribution(enc)
require.Nil(err)
require.Equal(mintGroupUniversal, res.Group)
require.Equal(uint64(123), res.Batch)
Expand Down
12 changes: 0 additions & 12 deletions common/mint.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,6 @@ func (tx *Transaction) AddUniversalMintInput(batch uint64, amount Integer) {
})
}

func (m *MintDistribution) CompressMarshal() []byte {
return compress(m.Marshal())
}

func DecompressUnmarshalMintDistribution(b []byte) (*MintDistribution, error) {
d := decompress(b)
if d == nil {
d = b
}
return UnmarshalMintDistribution(d)
}

func (m *MintDistribution) Marshal() []byte {
enc := NewMinimumEncoder()
switch m.Group {
Expand Down
12 changes: 0 additions & 12 deletions common/round.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ func (m *RoundLink) Copy() *RoundLink {
return &RoundLink{Self: m.Self, External: m.External}
}

func (r *Round) CompressMarshal() []byte {
return compress(r.Marshal())
}

func DecompressUnmarshalRound(b []byte) (*Round, error) {
d := decompress(b)
if d == nil {
d = b
}
return UnmarshalRound(d)
}

func (r *Round) Marshal() []byte {
enc := NewMinimumEncoder()
enc.Write(r.Hash[:])
Expand Down
6 changes: 3 additions & 3 deletions common/round_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ func TestRound(t *testing.T) {
},
}

rb := round.CompressMarshal()
require.Equal("0000000028b52ffd0300c118533cb104007777000141fcf8ecefae9071c8e9c779bdad09bd2f27a1edccd4df012e929a71a7cef15e3b4918d62413a03a21a89b486a41017f6b2776a9a72ba2c34605011e110bda1d000000000000007b00000000000001c8000200b75137647312fd194412a1df91fce7c9005743953a373613b08bd8e2827dcc8585f24ace862a82a0f2feb2cab0f893f5f267969ed0d71b4ecb7cb2387e016a", hex.EncodeToString(rb))
rb := round.Marshal()
require.Equal("7777000141fcf8ecefae9071c8e9c779bdad09bd2f27a1edccd4df012e929a71a7cef15e3b4918d62413a03a21a89b486a41017f6b2776a9a72ba2c34605011e110bda1d000000000000007b00000000000001c8000200b75137647312fd194412a1df91fce7c9005743953a373613b08bd8e2827dcc8585f24ace862a82a0f2feb2cab0f893f5f267969ed0d71b4ecb7cb2387e016a", hex.EncodeToString(rb))

un, err := DecompressUnmarshalRound(rb)
un, err := UnmarshalRound(rb)
require.Nil(err)
require.Equal("41fcf8ecefae9071c8e9c779bdad09bd2f27a1edccd4df012e929a71a7cef15e", un.Hash.String())
}
13 changes: 1 addition & 12 deletions common/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,7 @@ func DecompressUnmarshalVersionedTransaction(val []byte) (*VersionedTransaction,
}

func UnmarshalVersionedTransaction(val []byte) (*VersionedTransaction, error) {
ver, err := unmarshalVersionedTransaction(val)
if err != nil {
return nil, err
}
if config.Debug {
ret1 := ver.marshal()
ret2 := ver.payloadMarshal() // FIXME remove this
if !bytes.Equal(val, ret1) && !bytes.Equal(val, ret2) {
return nil, fmt.Errorf("unmarshal malformed %d %d %d", len(val), len(ret1), len(ret2))
}
}
return ver, nil
return unmarshalVersionedTransaction(val)
}

func (ver *VersionedTransaction) CompressMarshal() []byte {
Expand Down
5 changes: 0 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,6 @@ func kernelCmd(c *cli.Context) error {
}
defer store.Close()

err = store.OneTimeFixMintPrefix()
if err != nil {
return err
}

addr := fmt.Sprintf(":%d", c.Int("port"))
node, err := kernel.SetupNode(custom, store, cache, addr, c.String("dir"))
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions storage/badger_mint.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (s *BadgerStore) ReadMintDistributions(offset, count uint64) ([]*common.Min
if err != nil {
return nil, nil, err
}
data, err := common.DecompressUnmarshalMintDistribution(ival)
data, err := common.UnmarshalMintDistribution(ival)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -83,7 +83,7 @@ func (s *BadgerStore) ReadLastMintDistribution(batch uint64) (*common.MintDistri
if err != nil {
return nil, err
}
data, err := common.DecompressUnmarshalMintDistribution(ival)
data, err := common.UnmarshalMintDistribution(ival)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -140,12 +140,12 @@ func readMintInput(txn *badger.Txn, mint *common.MintData) (*common.MintDistribu
if err != nil {
return nil, err
}
return common.DecompressUnmarshalMintDistribution(ival)
return common.UnmarshalMintDistribution(ival)
}

func writeMintDistribution(txn *badger.Txn, mint *common.MintData, tx crypto.Hash) error {
key := graphMintKey(mint.Batch)
val := mint.Distribute(tx).CompressMarshal()
val := mint.Distribute(tx).Marshal()
return txn.Set(key, val)
}

Expand Down
63 changes: 0 additions & 63 deletions storage/badger_mint_fix.go

This file was deleted.

15 changes: 9 additions & 6 deletions storage/badger_round.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (s *BadgerStore) UpdateEmptyHeadRound(node crypto.Hash, number uint64, refe
return err
}
err = writeRound(txn, node, &common.Round{
Hash: node,
NodeId: node,
Number: number,
References: references,
Expand Down Expand Up @@ -145,6 +146,7 @@ func startNewRound(txn *badger.Txn, node crypto.Hash, number uint64, references
}

return writeRound(txn, node, &common.Round{
Hash: node,
NodeId: node,
Number: number,
References: references,
Expand Down Expand Up @@ -187,19 +189,20 @@ func readRound(txn *badger.Txn, hash crypto.Hash) (*common.Round, error) {
return nil, err
}

round, err := common.DecompressUnmarshalRound(ival)
if err != nil || round.Hash.HasValue() {
return round, err
round, err := common.UnmarshalRound(ival)
if err != nil {
return nil, err
}
if !round.Hash.HasValue() {
panic(hash)
}

// FIXME because old code forgot to write the hash
round.Hash = hash
return round, nil
}

func writeRound(txn *badger.Txn, hash crypto.Hash, round *common.Round) error {
key := graphRoundKey(hash)
val := round.CompressMarshal()
val := round.Marshal()
return txn.Set(key, val)
}

Expand Down

0 comments on commit 883f625

Please sign in to comment.