Skip to content

Commit

Permalink
chore: do some optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
fearlessfe committed Dec 22, 2024
1 parent 6568332 commit 77a22b5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ GOBIN = ./build/bin
GO ?= latest
GORUN = go run

GIT_COMMIT := $(shell git rev-parse HEAD)
GIT_COMMIT := $(shell git rev-parse --short=8 HEAD)
GIT_DATE := $(shell git log -1 --format=%ci | cut -d ' ' -f 1)

#? shisui: Build shisui
Expand All @@ -21,7 +21,7 @@ shisui:

#? shisui-image: Build shisui image
shisui-image:
docker build -t ghcr.io/optimism-java/shisui:latest -f Dockerfile .
docker build -t ghcr.io/zen-eth/shisui:latest -f Dockerfile .

#? fmt: Ensure consistent code formatting.
fmt:
Expand Down
5 changes: 5 additions & 0 deletions cmd/shisui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/optimism-java/shisui2/web3"
"github.com/protolambda/zrnt/eth2/configs"
"github.com/urfave/cli/v2"
"go.uber.org/automaxprocs/maxprocs"
)

var (
Expand Down Expand Up @@ -111,6 +112,10 @@ func init() {
flags.AutoEnvVars(app.Flags, "SHISUI")

app.Before = func(ctx *cli.Context) error {
_, err := maxprocs.Set() // Automatically set GOMAXPROCS to match Linux container CPU quota.
if err != nil {
return err
}
flags.MigrateGlobalFlags(ctx)
if err := debug.Setup(ctx); err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
github.com/stretchr/testify v1.10.0
github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834
github.com/urfave/cli/v2 v2.27.5
go.uber.org/automaxprocs v1.6.0
go.uber.org/zap v1.27.0
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f
golang.org/x/text v0.21.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U=
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
Expand Down Expand Up @@ -254,6 +256,8 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs=
go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
Expand Down
9 changes: 4 additions & 5 deletions history/history_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (h *Network) GetBlockHeader(blockHash []byte) (*types.Header, error) {
}
err = h.portalProtocol.Put(contentKey, contentId, content)
if err != nil {
h.log.Error("failed to store content in getBlockHeader", "contentKey", hexutil.Encode(contentKey), "content", hexutil.Encode(content))
h.log.Error("failed to store content in getBlockHeader", "contentKey", hexutil.Encode(contentKey), "err", err)
}
return header, nil
}
Expand Down Expand Up @@ -199,7 +199,7 @@ func (h *Network) GetBlockBody(blockHash []byte) (*types.Body, error) {
}
err = h.portalProtocol.Put(contentKey, contentId, content)
if err != nil {
h.log.Error("failed to store content in getBlockBody", "contentKey", hexutil.Encode(contentKey), "content", hexutil.Encode(content))
h.log.Error("failed to store content in getBlockBody", "contentKey", hexutil.Encode(contentKey), "err", err)
}
return body, nil
}
Expand Down Expand Up @@ -248,7 +248,7 @@ func (h *Network) GetReceipts(blockHash []byte) ([]*types.Receipt, error) {
}
err = h.portalProtocol.Put(contentKey, contentId, content)
if err != nil {
h.log.Error("failed to store content in getReceipts", "contentKey", hexutil.Encode(contentKey), "content", hexutil.Encode(content))
h.log.Error("failed to store content in getReceipts", "contentKey", hexutil.Encode(contentKey), "err", err)
}
return receipts, nil
}
Expand Down Expand Up @@ -564,8 +564,7 @@ func (h *Network) validateContents(contentKeys [][]byte, contents [][]byte) erro
contentKey := contentKeys[i]
err := h.validateContent(contentKey, content)
if err != nil {
h.log.Error("content validate failed", "contentKey", hexutil.Encode(contentKey), "content", hexutil.Encode(content), "err", err)
return fmt.Errorf("content validate failed with content key %x and content %x", contentKey, content)
return fmt.Errorf("content validate failed with content key %x and content %x, err is %v", contentKey, content, err)
}
contentId := h.portalProtocol.ToContentId(contentKey)
_ = h.portalProtocol.Put(contentKey, contentId, content)
Expand Down

0 comments on commit 77a22b5

Please sign in to comment.