From a31007e4d27b365d068e9ed9f481e1f94e7810c2 Mon Sep 17 00:00:00 2001 From: tac0turtle Date: Wed, 14 May 2025 09:01:07 -0400 Subject: [PATCH 1/7] remove maxblobsize from da interface --- .github/workflows/check_consts_drift.yml | 61 ++++++++++++++++++++++++ core/da/da.go | 3 -- da/go.mod | 3 ++ da/go.sum | 6 +++ da/jsonrpc/client.go | 18 +------ da/jsonrpc/internal/consts.go | 34 +++++++++++++ 6 files changed, 106 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/check_consts_drift.yml create mode 100644 da/jsonrpc/internal/consts.go diff --git a/.github/workflows/check_consts_drift.yml b/.github/workflows/check_consts_drift.yml new file mode 100644 index 0000000000..babbc05ccc --- /dev/null +++ b/.github/workflows/check_consts_drift.yml @@ -0,0 +1,61 @@ +name: Check Celestia App Consts Drift + +on: + schedule: + - cron: "0 0 * * 0" # Run every Sunday at midnight UTC + workflow_dispatch: # Allows manual triggering + pull_request: + +jobs: + check_drift: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Fetch Celestia App Consts + id: fetch_celestia_consts + run: | + curl -sSL https://raw.githubusercontent.com/celestiaorg/celestia-app/main/pkg/appconsts/initial_consts.go -o /tmp/celestia_initial_consts.go + if [ $? -ne 0 ]; then + echo "Failed to download Celestia app consts file." + exit 1 + fi + echo "celestia_file_path=/tmp/celestia_initial_consts.go" >> $GITHUB_OUTPUT + + - name: Compare Files + id: diff_files + run: | + LOCAL_FILE="da/jsonrpc/internal/consts.go" # Relative path from repo root + CELESTIA_FILE="${{ steps.fetch_celestia_consts.outputs.celestia_file_path }}" + + if [ ! -f "$LOCAL_FILE" ]; then + echo "Local consts.go file not found at $LOCAL_FILE" + exit 1 + fi + + echo "Comparing $LOCAL_FILE (excluding last line) with $CELESTIA_FILE (excluding last line)" + + # Create temporary files without the last line + LOCAL_FILE_TMP=$(mktemp) + CELESTIA_FILE_TMP=$(mktemp) + + head -n -1 "$LOCAL_FILE" > "$LOCAL_FILE_TMP" + head -n -1 "$CELESTIA_FILE" > "$CELESTIA_FILE_TMP" + + diff_output=$(diff -u "$LOCAL_FILE_TMP" "$CELESTIA_FILE_TMP") + + # Clean up temporary files + rm "$LOCAL_FILE_TMP" + rm "$CELESTIA_FILE_TMP" + + if [ $? -ne 0 ]; then + echo "Files are different (excluding last line)." + echo "diff_output<> $GITHUB_OUTPUT + echo "$diff_output" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + echo "files_differ=true" >> $GITHUB_OUTPUT + else + echo "Files are identical (excluding last line)." + echo "files_differ=false" >> $GITHUB_OUTPUT + fi diff --git a/core/da/da.go b/core/da/da.go index d765b7e353..3b6817f6d7 100644 --- a/core/da/da.go +++ b/core/da/da.go @@ -9,9 +9,6 @@ import ( // DA defines very generic interface for interaction with Data Availability layers. type DA interface { - // MaxBlobSize returns the max blob size - MaxBlobSize(ctx context.Context) (uint64, error) - // Get returns Blob for each given ID, or an error. // // Error should be returned if ID is not formatted properly, there is no Blob for given ID or any other client-level diff --git a/da/go.mod b/da/go.mod index 5ed4a8604e..f6a0673c12 100644 --- a/da/go.mod +++ b/da/go.mod @@ -6,6 +6,7 @@ replace github.com/rollkit/rollkit/core => ../core require ( cosmossdk.io/log v1.5.1 + github.com/celestiaorg/go-square/v2 v2.2.0 github.com/filecoin-project/go-jsonrpc v0.7.1 github.com/rollkit/rollkit/core v0.0.0-20250312114929-104787ba1a4c github.com/stretchr/testify v1.10.0 @@ -35,8 +36,10 @@ require ( go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.0 // indirect golang.org/x/arch v0.15.0 // indirect + golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect golang.org/x/sys v0.31.0 // indirect golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect + google.golang.org/protobuf v1.36.6 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/da/go.sum b/da/go.sum index 8bc9e5a54f..0456132578 100644 --- a/da/go.sum +++ b/da/go.sum @@ -8,6 +8,8 @@ github.com/bytedance/sonic v1.13.2/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1 github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY= github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI= +github.com/celestiaorg/go-square/v2 v2.2.0 h1:zJnUxCYc65S8FgUfVpyG/osDcsnjzo/JSXw/Uwn8zp4= +github.com/celestiaorg/go-square/v2 v2.2.0/go.mod h1:j8kQUqJLYtcvCQMQV6QjEhUdaF7rBTXF74g8LbkR0Co= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4= @@ -123,6 +125,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb h1:c0vyKkb6yr3KR7jEfJaOSv4lG7xPkbN6r52aJz1d8a8= +golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= @@ -189,6 +193,8 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= +google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= diff --git a/da/jsonrpc/client.go b/da/jsonrpc/client.go index 9f640d8d18..1b66a64bc3 100644 --- a/da/jsonrpc/client.go +++ b/da/jsonrpc/client.go @@ -11,6 +11,7 @@ import ( "github.com/filecoin-project/go-jsonrpc" "github.com/rollkit/rollkit/core/da" + internal "github.com/rollkit/rollkit/da/jsonrpc/internal" ) //go:generate mockgen -destination=mocks/api.go -package=mocks . Module @@ -36,17 +37,6 @@ type API struct { } } -// MaxBlobSize returns the max blob size -func (api *API) MaxBlobSize(ctx context.Context) (uint64, error) { - res, err := api.Internal.MaxBlobSize(ctx) - if err != nil { - api.Logger.Error("RPC call failed", "method", "MaxBlobSize", "error", err) - } else { - api.Logger.Debug("RPC call successful", "method", "MaxBlobSize", "result", res) - } - return res, err -} - // Get returns Blob for each given ID, or an error. func (api *API) Get(ctx context.Context, ids []da.ID, _ []byte) ([]da.Blob, error) { api.Logger.Debug("Making RPC call", "method", "Get", "num_ids", len(ids), "namespace", string(api.Namespace)) @@ -135,11 +125,7 @@ func (api *API) Submit(ctx context.Context, blobs []da.Blob, gasPrice float64, _ // SubmitWithOptions submits the Blobs to Data Availability layer with additional options. // It checks blobs against MaxBlobSize and submits only those that fit. func (api *API) SubmitWithOptions(ctx context.Context, inputBlobs []da.Blob, gasPrice float64, _ []byte, options []byte) ([]da.ID, error) { - maxBlobSize, err := api.MaxBlobSize(ctx) - if err != nil { - api.Logger.Error("Failed to get MaxBlobSize for blob filtering", "error", err) - return nil, fmt.Errorf("failed to get max blob size for submission: %w", err) - } + maxBlobSize := uint64(internal.DefaultMaxBytes) var ( blobsToSubmit [][]byte = make([][]byte, 0, len(inputBlobs)) diff --git a/da/jsonrpc/internal/consts.go b/da/jsonrpc/internal/consts.go new file mode 100644 index 0000000000..94d4503509 --- /dev/null +++ b/da/jsonrpc/internal/consts.go @@ -0,0 +1,34 @@ +package appconsts + +import ( + "time" + + "github.com/celestiaorg/go-square/v2/share" +) + +// The following defaults correspond to initial parameters of the network that can be changed, not via app versions +// but other means such as on-chain governance, or the node's local config +const ( + // DefaultGovMaxSquareSize is the default value for the governance modifiable + // max square size. + DefaultGovMaxSquareSize = 64 + + // DefaultMaxBytes is the default value for the governance modifiable + // maximum number of bytes allowed in a valid block. + DefaultMaxBytes = DefaultGovMaxSquareSize * DefaultGovMaxSquareSize * share.ContinuationSparseShareContentSize + + // DefaultMinGasPrice is the default min gas price that gets set in the app.toml file. + // The min gas price acts as a filter. Transactions below that limit will not pass + // a node's `CheckTx` and thus not be proposed by that node. + DefaultMinGasPrice = 0.002 // utia + + // DefaultUnbondingTime is the default time a validator must wait + // to unbond in a proof of stake system. Any validator within this + // time can be subject to slashing under conditions of misbehavior. + DefaultUnbondingTime = 3 * 7 * 24 * time.Hour + + // DefaultNetworkMinGasPrice is used by x/minfee to prevent transactions from being + // included in a block if they specify a gas price lower than this. + // Only applies to app version >= 2 + DefaultNetworkMinGasPrice = 0.000001 // utia +) From 86569acc1375559736fb5e20dcaba8f795134735 Mon Sep 17 00:00:00 2001 From: tac0turtle Date: Wed, 14 May 2025 09:14:00 -0400 Subject: [PATCH 2/7] tidy --- rollups/evm/based/go.mod | 1 + rollups/evm/based/go.sum | 2 ++ rollups/evm/single/go.mod | 1 + rollups/evm/single/go.sum | 2 ++ rollups/testapp/go.mod | 1 + rollups/testapp/go.sum | 2 ++ 6 files changed, 9 insertions(+) diff --git a/rollups/evm/based/go.mod b/rollups/evm/based/go.mod index acf697944d..72a73ebac6 100644 --- a/rollups/evm/based/go.mod +++ b/rollups/evm/based/go.mod @@ -38,6 +38,7 @@ require ( github.com/bytedance/sonic/loader v0.2.4 // indirect github.com/celestiaorg/go-header v0.6.5 // indirect github.com/celestiaorg/go-libp2p-messenger v0.2.2 // indirect + github.com/celestiaorg/go-square/v2 v2.2.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cloudwego/base64x v0.1.5 // indirect github.com/consensys/bavard v0.1.22 // indirect diff --git a/rollups/evm/based/go.sum b/rollups/evm/based/go.sum index 953b1cc852..f456f596e5 100644 --- a/rollups/evm/based/go.sum +++ b/rollups/evm/based/go.sum @@ -89,6 +89,8 @@ github.com/celestiaorg/go-header v0.6.5 h1:4zR666BypzaEvmIAkoowEklZ6Kj+4wIpYh4bl github.com/celestiaorg/go-header v0.6.5/go.mod h1:BTIw7TGoH3FabsHkxNGQdFZy4WjQ3fWPVjKrPjWIVZg= github.com/celestiaorg/go-libp2p-messenger v0.2.2 h1:osoUfqjss7vWTIZrrDSy953RjQz+ps/vBFE7bychLEc= github.com/celestiaorg/go-libp2p-messenger v0.2.2/go.mod h1:oTCRV5TfdO7V/k6nkx7QjQzGrWuJbupv+0o1cgnY2i4= +github.com/celestiaorg/go-square/v2 v2.2.0 h1:zJnUxCYc65S8FgUfVpyG/osDcsnjzo/JSXw/Uwn8zp4= +github.com/celestiaorg/go-square/v2 v2.2.0/go.mod h1:j8kQUqJLYtcvCQMQV6QjEhUdaF7rBTXF74g8LbkR0Co= github.com/celestiaorg/utils v0.1.0 h1:WsP3O8jF7jKRgLNFmlDCwdThwOFMFxg0MnqhkLFVxPo= github.com/celestiaorg/utils v0.1.0/go.mod h1:vQTh7MHnvpIeCQZ2/Ph+w7K1R2UerDheZbgJEJD2hSU= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= diff --git a/rollups/evm/single/go.mod b/rollups/evm/single/go.mod index 21da01fb0d..3cf33bc5fe 100644 --- a/rollups/evm/single/go.mod +++ b/rollups/evm/single/go.mod @@ -39,6 +39,7 @@ require ( github.com/bytedance/sonic/loader v0.2.4 // indirect github.com/celestiaorg/go-header v0.6.5 // indirect github.com/celestiaorg/go-libp2p-messenger v0.2.2 // indirect + github.com/celestiaorg/go-square/v2 v2.2.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cloudwego/base64x v0.1.5 // indirect github.com/consensys/bavard v0.1.22 // indirect diff --git a/rollups/evm/single/go.sum b/rollups/evm/single/go.sum index 953b1cc852..f456f596e5 100644 --- a/rollups/evm/single/go.sum +++ b/rollups/evm/single/go.sum @@ -89,6 +89,8 @@ github.com/celestiaorg/go-header v0.6.5 h1:4zR666BypzaEvmIAkoowEklZ6Kj+4wIpYh4bl github.com/celestiaorg/go-header v0.6.5/go.mod h1:BTIw7TGoH3FabsHkxNGQdFZy4WjQ3fWPVjKrPjWIVZg= github.com/celestiaorg/go-libp2p-messenger v0.2.2 h1:osoUfqjss7vWTIZrrDSy953RjQz+ps/vBFE7bychLEc= github.com/celestiaorg/go-libp2p-messenger v0.2.2/go.mod h1:oTCRV5TfdO7V/k6nkx7QjQzGrWuJbupv+0o1cgnY2i4= +github.com/celestiaorg/go-square/v2 v2.2.0 h1:zJnUxCYc65S8FgUfVpyG/osDcsnjzo/JSXw/Uwn8zp4= +github.com/celestiaorg/go-square/v2 v2.2.0/go.mod h1:j8kQUqJLYtcvCQMQV6QjEhUdaF7rBTXF74g8LbkR0Co= github.com/celestiaorg/utils v0.1.0 h1:WsP3O8jF7jKRgLNFmlDCwdThwOFMFxg0MnqhkLFVxPo= github.com/celestiaorg/utils v0.1.0/go.mod h1:vQTh7MHnvpIeCQZ2/Ph+w7K1R2UerDheZbgJEJD2hSU= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= diff --git a/rollups/testapp/go.mod b/rollups/testapp/go.mod index 5a7215bee9..e8de21c70f 100644 --- a/rollups/testapp/go.mod +++ b/rollups/testapp/go.mod @@ -29,6 +29,7 @@ require ( github.com/bytedance/sonic/loader v0.2.4 // indirect github.com/celestiaorg/go-header v0.6.5 // indirect github.com/celestiaorg/go-libp2p-messenger v0.2.2 // indirect + github.com/celestiaorg/go-square/v2 v2.2.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cloudwego/base64x v0.1.5 // indirect github.com/containerd/cgroups v1.1.0 // indirect diff --git a/rollups/testapp/go.sum b/rollups/testapp/go.sum index c2841bb240..2516d50b31 100644 --- a/rollups/testapp/go.sum +++ b/rollups/testapp/go.sum @@ -35,6 +35,8 @@ github.com/celestiaorg/go-header v0.6.5 h1:4zR666BypzaEvmIAkoowEklZ6Kj+4wIpYh4bl github.com/celestiaorg/go-header v0.6.5/go.mod h1:BTIw7TGoH3FabsHkxNGQdFZy4WjQ3fWPVjKrPjWIVZg= github.com/celestiaorg/go-libp2p-messenger v0.2.2 h1:osoUfqjss7vWTIZrrDSy953RjQz+ps/vBFE7bychLEc= github.com/celestiaorg/go-libp2p-messenger v0.2.2/go.mod h1:oTCRV5TfdO7V/k6nkx7QjQzGrWuJbupv+0o1cgnY2i4= +github.com/celestiaorg/go-square/v2 v2.2.0 h1:zJnUxCYc65S8FgUfVpyG/osDcsnjzo/JSXw/Uwn8zp4= +github.com/celestiaorg/go-square/v2 v2.2.0/go.mod h1:j8kQUqJLYtcvCQMQV6QjEhUdaF7rBTXF74g8LbkR0Co= github.com/celestiaorg/utils v0.1.0 h1:WsP3O8jF7jKRgLNFmlDCwdThwOFMFxg0MnqhkLFVxPo= github.com/celestiaorg/utils v0.1.0/go.mod h1:vQTh7MHnvpIeCQZ2/Ph+w7K1R2UerDheZbgJEJD2hSU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= From 8aefa9faad1b7da99b8b0f2ea42fd024c9c0f55a Mon Sep 17 00:00:00 2001 From: Marko Date: Wed, 14 May 2025 09:14:13 -0400 Subject: [PATCH 3/7] Potential fix for code scanning alert no. 39: Workflow does not contain permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- .github/workflows/check_consts_drift.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/check_consts_drift.yml b/.github/workflows/check_consts_drift.yml index babbc05ccc..f2b566bf86 100644 --- a/.github/workflows/check_consts_drift.yml +++ b/.github/workflows/check_consts_drift.yml @@ -1,4 +1,6 @@ name: Check Celestia App Consts Drift +permissions: + contents: read on: schedule: From f321aa0f82802b5be4836dbcfd14cac7bccc134f Mon Sep 17 00:00:00 2001 From: tac0turtle Date: Wed, 14 May 2025 11:18:36 -0400 Subject: [PATCH 4/7] fix test --- da/jsonrpc/client.go | 11 +++++----- da/jsonrpc/proxy_test.go | 47 ++++++++++------------------------------ 2 files changed, 17 insertions(+), 41 deletions(-) diff --git a/da/jsonrpc/client.go b/da/jsonrpc/client.go index 1b66a64bc3..e008d3d067 100644 --- a/da/jsonrpc/client.go +++ b/da/jsonrpc/client.go @@ -21,10 +21,10 @@ type Module interface { // API defines the jsonrpc service module API type API struct { - Logger log.Logger - Namespace []byte - Internal struct { - MaxBlobSize func(ctx context.Context) (uint64, error) `perm:"read"` + Logger log.Logger + Namespace []byte + MaxBlobSize uint64 + Internal struct { Get func(ctx context.Context, ids []da.ID, ns []byte) ([]da.Blob, error) `perm:"read"` GetIDs func(ctx context.Context, height uint64, ns []byte) (*da.GetIDsResult, error) `perm:"read"` GetProofs func(ctx context.Context, ids []da.ID, ns []byte) ([]da.Proof, error) `perm:"read"` @@ -125,7 +125,7 @@ func (api *API) Submit(ctx context.Context, blobs []da.Blob, gasPrice float64, _ // SubmitWithOptions submits the Blobs to Data Availability layer with additional options. // It checks blobs against MaxBlobSize and submits only those that fit. func (api *API) SubmitWithOptions(ctx context.Context, inputBlobs []da.Blob, gasPrice float64, _ []byte, options []byte) ([]da.ID, error) { - maxBlobSize := uint64(internal.DefaultMaxBytes) + maxBlobSize := api.MaxBlobSize var ( blobsToSubmit [][]byte = make([][]byte, 0, len(inputBlobs)) @@ -233,6 +233,7 @@ func newClient(ctx context.Context, logger log.Logger, addr string, authHeader h var multiCloser multiClientCloser var client Client client.DA.Logger = logger + client.DA.MaxBlobSize = internal.DefaultMaxBytes namespaceBytes, err := hex.DecodeString(namespace) if err != nil { return nil, fmt.Errorf("failed to decode namespace: %w", err) diff --git a/da/jsonrpc/proxy_test.go b/da/jsonrpc/proxy_test.go index 8e25fc333d..fadbd735e9 100644 --- a/da/jsonrpc/proxy_test.go +++ b/da/jsonrpc/proxy_test.go @@ -26,6 +26,8 @@ const ( ServerPort = "3450" // ClientURL is the url to dial for the test JSONRPC client ClientURL = "http://localhost:3450" + + testMaxBlobSize = 100 ) var testNamespace = []byte("test") @@ -221,9 +223,9 @@ func TestSubmitWithOptions(t *testing.T) { // Helper function to create a client with a mocked internal API createMockedClient := func(internalAPI *mocks.DA) *proxy.Client { client := &proxy.Client{} - client.DA.Internal.MaxBlobSize = internalAPI.MaxBlobSize client.DA.Internal.SubmitWithOptions = internalAPI.SubmitWithOptions client.DA.Namespace = testNamespace + client.DA.MaxBlobSize = testMaxBlobSize client.DA.Logger = log.NewTestLogger(t) return client } @@ -234,9 +236,7 @@ func TestSubmitWithOptions(t *testing.T) { blobs := []coreda.Blob{[]byte("blob1"), []byte("blob2")} expectedIDs := []coreda.ID{[]byte("id1"), []byte("id2")} - maxSize := uint64(100) - mockAPI.On("MaxBlobSize", ctx).Return(maxSize, nil).Once() mockAPI.On("SubmitWithOptions", ctx, blobs, gasPrice, testNamespace, testOptions).Return(expectedIDs, nil).Once() ids, err := client.DA.SubmitWithOptions(ctx, blobs, gasPrice, testNamespace, testOptions) @@ -250,10 +250,8 @@ func TestSubmitWithOptions(t *testing.T) { mockAPI := mocks.NewDA(t) client := createMockedClient(mockAPI) - blobs := []coreda.Blob{[]byte("small"), []byte("this blob is definitely too large")} - maxSize := uint64(20) - - mockAPI.On("MaxBlobSize", ctx).Return(maxSize, nil).Once() + largerBlob := make([]byte, testMaxBlobSize+1) + blobs := []coreda.Blob{largerBlob, []byte("this blob is definitely too large")} _, err := client.DA.SubmitWithOptions(ctx, blobs, gasPrice, testNamespace, testOptions) @@ -265,10 +263,11 @@ func TestSubmitWithOptions(t *testing.T) { mockAPI := mocks.NewDA(t) client := createMockedClient(mockAPI) - blobs := []coreda.Blob{[]byte("blobA"), []byte("blobB"), []byte("blobC")} - maxSize := uint64(12) + blobsizes := make([]byte, testMaxBlobSize/3) + blobsizesOver := make([]byte, testMaxBlobSize) + + blobs := []coreda.Blob{blobsizes, blobsizes, blobsizesOver} - mockAPI.On("MaxBlobSize", ctx).Return(maxSize, nil).Once() expectedSubmitBlobs := []coreda.Blob{blobs[0], blobs[1]} expectedIDs := []coreda.ID{[]byte("idA"), []byte("idB")} mockAPI.On("SubmitWithOptions", ctx, expectedSubmitBlobs, gasPrice, testNamespace, testOptions).Return(expectedIDs, nil).Once() @@ -284,10 +283,8 @@ func TestSubmitWithOptions(t *testing.T) { mockAPI := mocks.NewDA(t) client := createMockedClient(mockAPI) - blobs := []coreda.Blob{[]byte("this first blob is too large"), []byte("small")} - maxSize := uint64(20) - - mockAPI.On("MaxBlobSize", ctx).Return(maxSize, nil).Once() + largerBlob := make([]byte, testMaxBlobSize+1) + blobs := []coreda.Blob{largerBlob, []byte("small")} ids, err := client.DA.SubmitWithOptions(ctx, blobs, gasPrice, testNamespace, testOptions) @@ -304,8 +301,6 @@ func TestSubmitWithOptions(t *testing.T) { client := createMockedClient(mockAPI) var blobs []coreda.Blob - maxSize := uint64(100) - mockAPI.On("MaxBlobSize", ctx).Return(maxSize, nil).Once() ids, err := client.DA.SubmitWithOptions(ctx, blobs, gasPrice, testNamespace, testOptions) @@ -316,33 +311,13 @@ func TestSubmitWithOptions(t *testing.T) { mockAPI.AssertExpectations(t) }) - t.Run("Error Getting MaxBlobSize", func(t *testing.T) { - mockAPI := mocks.NewDA(t) - client := createMockedClient(mockAPI) - - blobs := []coreda.Blob{[]byte("blob1")} - expectedError := errors.New("failed to get max size") - - mockAPI.On("MaxBlobSize", ctx).Return(uint64(0), expectedError).Once() - - ids, err := client.DA.SubmitWithOptions(ctx, blobs, gasPrice, testNamespace, testOptions) - - require.Error(t, err) - assert.ErrorContains(t, err, "failed to get max blob size for submission") - assert.ErrorIs(t, err, expectedError) - assert.Nil(t, ids) - mockAPI.AssertExpectations(t) - }) - t.Run("Error During SubmitWithOptions RPC", func(t *testing.T) { mockAPI := mocks.NewDA(t) client := createMockedClient(mockAPI) blobs := []coreda.Blob{[]byte("blob1")} - maxSize := uint64(100) expectedError := errors.New("rpc submit failed") - mockAPI.On("MaxBlobSize", ctx).Return(maxSize, nil).Once() mockAPI.On("SubmitWithOptions", ctx, blobs, gasPrice, testNamespace, testOptions).Return(nil, expectedError).Once() ids, err := client.DA.SubmitWithOptions(ctx, blobs, gasPrice, testNamespace, testOptions) From fa71c465d6ba0ee009a43aa263a80b8d35a8ea92 Mon Sep 17 00:00:00 2001 From: tac0turtle Date: Wed, 14 May 2025 11:27:27 -0400 Subject: [PATCH 5/7] action --- .github/workflows/check_consts_drift.yml | 55 ++++++++++++++++++------ 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/.github/workflows/check_consts_drift.yml b/.github/workflows/check_consts_drift.yml index f2b566bf86..820ffbf4a3 100644 --- a/.github/workflows/check_consts_drift.yml +++ b/.github/workflows/check_consts_drift.yml @@ -1,6 +1,7 @@ name: Check Celestia App Consts Drift permissions: contents: read + issues: write # Added issues: write permission on: schedule: @@ -35,29 +36,57 @@ jobs: echo "Local consts.go file not found at $LOCAL_FILE" exit 1 fi + if [ ! -f "$CELESTIA_FILE" ]; then + echo "Fetched Celestia consts file not found at $CELESTIA_FILE" + # This should ideally be caught by the previous step's check + exit 1 + fi echo "Comparing $LOCAL_FILE (excluding last line) with $CELESTIA_FILE (excluding last line)" - # Create temporary files without the last line LOCAL_FILE_TMP=$(mktemp) CELESTIA_FILE_TMP=$(mktemp) + # Ensure temporary files are removed on exit + trap 'rm -f "$LOCAL_FILE_TMP" "$CELESTIA_FILE_TMP"' EXIT head -n -1 "$LOCAL_FILE" > "$LOCAL_FILE_TMP" + if [ $? -ne 0 ]; then + echo "Error processing local file '$LOCAL_FILE' with head." + exit 1 + fi head -n -1 "$CELESTIA_FILE" > "$CELESTIA_FILE_TMP" - - diff_output=$(diff -u "$LOCAL_FILE_TMP" "$CELESTIA_FILE_TMP") - - # Clean up temporary files - rm "$LOCAL_FILE_TMP" - rm "$CELESTIA_FILE_TMP" - if [ $? -ne 0 ]; then - echo "Files are different (excluding last line)." - echo "diff_output<> $GITHUB_OUTPUT - echo "$diff_output" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT - echo "files_differ=true" >> $GITHUB_OUTPUT + echo "Error processing fetched Celestia file '$CELESTIA_FILE' with head." + exit 1 + fi + + # Perform the diff and handle its exit code robustly + diff_command_output="" + if ! diff_command_output=$(diff -u "$LOCAL_FILE_TMP" "$CELESTIA_FILE_TMP"); then + # diff exited with non-zero status + diff_exit_code=$? + if [ $diff_exit_code -eq 1 ]; then + # Exit code 1 means files are different + echo "Files are different (excluding last line)." + echo "diff_output<> $GITHUB_OUTPUT + echo "$diff_command_output" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + echo "files_differ=true" >> $GITHUB_OUTPUT + else + # Exit code > 1 means diff encountered an error + echo "Error: diff command failed with exit code $diff_exit_code." + echo "Diff command output/error: $diff_command_output" + # Output error information for the issue + echo "diff_output<> $GITHUB_OUTPUT + echo "Diff command error (exit code $diff_exit_code):" >> $GITHUB_OUTPUT + echo "$diff_command_output" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + echo "files_differ=true" >> $GITHUB_OUTPUT # Treat as a difference to create an issue + # Optionally, exit with diff's error code to make the step fail clearly + # exit $diff_exit_code + fi else + # diff exited with 0, files are identical echo "Files are identical (excluding last line)." echo "files_differ=false" >> $GITHUB_OUTPUT fi From f361afe03c3eb6ba23e5f491439874774e6b6699 Mon Sep 17 00:00:00 2001 From: tac0turtle Date: Wed, 14 May 2025 11:33:39 -0400 Subject: [PATCH 6/7] fail on the action --- .github/workflows/check_consts_drift.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/check_consts_drift.yml b/.github/workflows/check_consts_drift.yml index 820ffbf4a3..64bf450a7e 100644 --- a/.github/workflows/check_consts_drift.yml +++ b/.github/workflows/check_consts_drift.yml @@ -1,12 +1,10 @@ name: Check Celestia App Consts Drift permissions: contents: read - issues: write # Added issues: write permission + issues: write on: - schedule: - - cron: "0 0 * * 0" # Run every Sunday at midnight UTC - workflow_dispatch: # Allows manual triggering + workflow_dispatch: pull_request: jobs: @@ -72,6 +70,7 @@ jobs: echo "$diff_command_output" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT echo "files_differ=true" >> $GITHUB_OUTPUT + exit 1 # Fail the step else # Exit code > 1 means diff encountered an error echo "Error: diff command failed with exit code $diff_exit_code." @@ -82,8 +81,7 @@ jobs: echo "$diff_command_output" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT echo "files_differ=true" >> $GITHUB_OUTPUT # Treat as a difference to create an issue - # Optionally, exit with diff's error code to make the step fail clearly - # exit $diff_exit_code + exit $diff_exit_code fi else # diff exited with 0, files are identical From 1e10c18530366a3378850f9039c08aee2f282dd8 Mon Sep 17 00:00:00 2001 From: tac0turtle Date: Wed, 14 May 2025 11:38:23 -0400 Subject: [PATCH 7/7] fix yamllint --- .github/workflows/check_consts_drift.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check_consts_drift.yml b/.github/workflows/check_consts_drift.yml index 64bf450a7e..f36f9848fd 100644 --- a/.github/workflows/check_consts_drift.yml +++ b/.github/workflows/check_consts_drift.yml @@ -1,7 +1,7 @@ name: Check Celestia App Consts Drift permissions: contents: read - issues: write + issues: write on: workflow_dispatch: