Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: genesis compress #6407

Merged
merged 4 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions fixtures/assets/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package assets

import (
"embed"
"io"
"path/filepath"

"github.com/filecoin-project/venus/venus-shared/types"
"github.com/klauspost/compress/zstd"
)

//go:embed genesis-car
Expand All @@ -14,7 +16,7 @@ func GetGenesis(networkType types.NetworkType) ([]byte, error) {
fileName := ""
switch networkType {
case types.NetworkForce:
fileName = "forcenet.car"
fileName = "forcenet.car.zst"
case types.NetworkInterop:
fileName = "interopnet.car.zst"
case types.NetworkButterfly:
Expand All @@ -25,7 +27,24 @@ func GetGenesis(networkType types.NetworkType) ([]byte, error) {
fileName = "mainnet.car.zst"
}

return carFS.ReadFile(filepath.Join("genesis-car", fileName))
file, err := carFS.Open(filepath.Join("genesis-car", fileName))
if err != nil {
return nil, err
}
defer file.Close() //nolint

decoder, err := zstd.NewReader(file)
if err != nil {
return nil, err
}
defer decoder.Close() //nolint

decompressedBytes, err := io.ReadAll(decoder)
if err != nil {
return nil, err
}

return decompressedBytes, nil
}

//go:embed proof-params
Expand Down
Binary file removed fixtures/assets/genesis-car/forcenet.car
Binary file not shown.
Binary file added fixtures/assets/genesis-car/forcenet.car.zst
Binary file not shown.
2 changes: 2 additions & 0 deletions tools/gengen/util/gengen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"testing"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/builtin"

"github.com/filecoin-project/go-state-types/abi"
Expand Down Expand Up @@ -60,6 +61,7 @@ const (

func TestGenGenLoading(t *testing.T) {
tf.IntegrationTest(t)
address.CurrentNetwork = address.Testnet

fi, err := os.CreateTemp("", "gengentest")
assert.NoError(t, err)
Expand Down
4 changes: 1 addition & 3 deletions venus-shared/actors/types/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"strings"

"github.com/ipfs/go-cid"
"github.com/multiformats/go-multihash"
mh "github.com/multiformats/go-multihash"
"github.com/multiformats/go-varint"
"golang.org/x/crypto/sha3"
Expand Down Expand Up @@ -515,7 +514,7 @@ func (h EthHash) String() string {
// Should ONLY be used for blocks and Filecoin messages. Eth transactions expect a different hashing scheme.
func (h EthHash) ToCid() cid.Cid {
// err is always nil
mh, _ := multihash.EncodeName(h[:], "blake2b-256")
mh, _ := mh.EncodeName(h[:], "blake2b-256")

return cid.NewCidV1(cid.DagCBOR, mh)
}
Expand Down Expand Up @@ -558,7 +557,6 @@ func handleHexStringPrefix(s string) string {
}

func EthHashFromCid(c cid.Cid) (EthHash, error) {
return ParseEthHash(c.Hash().HexString()[8:])
hash, found := bytes.CutPrefix(c.Bytes(), expectedHashPrefix)
if !found {
return EthHash{}, fmt.Errorf("CID does not have the expected prefix")
Expand Down
4 changes: 2 additions & 2 deletions venus-shared/types/actor_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestJSONMarshalling(t *testing.T) {
TipSetKey: NewTipSetKey(randomCid(t, rng)),
MsgCid: randomCid(t, rng),
},
`{"entries":[{"Flags":0,"Key":"key1","Codec":81,"Value":"dmFsdWUx"},{"Flags":0,"Key":"key2","Codec":82,"Value":"dmFsdWUy"}],"emitter":"t410fagkp3qx2f76maqot74jaiw3tzbxe76k76zrkl3xifk67isrnbn2sll3yua","reverted":false,"height":1001,"tipsetKey":[{"/":"bafkqacx3dag26sfht3qlcdi"}],"msgCid":{"/":"bafkqacrziziykd6uuf4islq"}}`,
`{"entries":[{"Flags":0,"Key":"key1","Codec":81,"Value":"dmFsdWUx"},{"Flags":0,"Key":"key2","Codec":82,"Value":"dmFsdWUy"}],"emitter":"f410fagkp3qx2f76maqot74jaiw3tzbxe76k76zrkl3xifk67isrnbn2sll3yua","reverted":false,"height":1001,"tipsetKey":[{"/":"bafkqacx3dag26sfht3qlcdi"}],"msgCid":{"/":"bafkqacrziziykd6uuf4islq"}}`,
),
)

Expand Down Expand Up @@ -66,7 +66,7 @@ func TestJSONMarshalling(t *testing.T) {
ToHeight: heightOf(100),
TipSetKey: randomTipSetKey(t, rng),
},
`{"addresses":["t410fagkp3qx2f76maqot74jaiw3tzbxe76k76zrkl3xifk67isrnbn2sll3yua","t410fagkp3qx2f76maqot74jaiw3tzbxe76k76zrkl3xifk67isrnbn2sll3yua"],"fields":{"key1":[{"codec":81,"value":"dmFsdWUx"}],"key2":[{"codec":82,"value":"dmFsdWUy"}]},"fromHeight":0,"toHeight":100,"tipsetKey":[{"/":"bafkqacxcqxwocuiukv4aq5i"}]}`,
`{"addresses":["f410fagkp3qx2f76maqot74jaiw3tzbxe76k76zrkl3xifk67isrnbn2sll3yua","f410fagkp3qx2f76maqot74jaiw3tzbxe76k76zrkl3xifk67isrnbn2sll3yua"],"fields":{"key1":[{"codec":81,"value":"dmFsdWUx"}],"key2":[{"codec":82,"value":"dmFsdWUy"}]},"fromHeight":0,"toHeight":100,"tipsetKey":[{"/":"bafkqacxcqxwocuiukv4aq5i"}]}`,
),
)
t.Run("actor event block",
Expand Down
Loading