From 0930af129c3e9cfe20bcd718400ce33b43a1e4aa Mon Sep 17 00:00:00 2001 From: Michael Buntarman Date: Tue, 24 Nov 2026 09:23:28 +0700 Subject: [PATCH] chore(infra): rebuild a sentry with a 10s RPC timeout --- .github/workflows/ci.yaml | 2 +- deployments/infra/README.md | 13 ++++++ .../infra/config/node/kwild-config.tmpl | 3 +- deployments/infra/config/node/values.go | 4 +- deployments/infra/config/node/values_test.go | 6 +++ .../lib/constructs/validator_set/node_test.go | 44 +++++++++++++++++++ 6 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 deployments/infra/lib/constructs/validator_set/node_test.go diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 450a1834e..e54c05f80 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -53,7 +53,7 @@ jobs: with: node-version: '20' - name: Run infra tests - run: go test -count=1 ./config/ ./lib/tn/ + run: go test -count=1 ./config/ ./config/node/ ./lib/tn/ ./lib/constructs/validator_set/ acceptance-test: runs-on: ubuntu-latest diff --git a/deployments/infra/README.md b/deployments/infra/README.md index bb32d36d7..7d6709c25 100644 --- a/deployments/infra/README.md +++ b/deployments/infra/README.md @@ -260,6 +260,19 @@ letters, digits, spaces and `._-:/()#,@[]+=&;{}!$*`, up to 200 characters. `lib/tn/security_group_test.go` pins the `prod` list, so change it there as well. Run `cdk diff` after changing the list. +## RPC Request Timeout + +Each node's rendered `config.toml` sets `[rpc] timeout = '10s'` (`config/node/kwild-config.tmpl`), down from kwild's +default of 20 s. Clients of these public RPC nodes commonly time out at 15 s, so with a 20 s limit a slow request can +keep them waiting past their own timeout. At 10 s kwild answers a slow request with a timeout error before they give up. + +The limit applies to every RPC request, so a broadcast that waits for its transaction to commit is also cut at 10 s, +before `broadcast_tx_timeout` (15 s) is reached. + +The launch template writes `config.toml` into the node's data directory at first boot only, so a node built from it +gets the setting and a running node keeps its own file. On a running node, set the same line in its `config.toml` and +restart kwild, or set `KWILD_RPC_TIMEOUT=10s` in the container environment, which overrides the file. + ## Useful Commands - `cdk deploy`: Deploy this stack to your default AWS account/region diff --git a/deployments/infra/config/node/kwild-config.tmpl b/deployments/infra/config/node/kwild-config.tmpl index e3a0820b5..7be98f610 100644 --- a/deployments/infra/config/node/kwild-config.tmpl +++ b/deployments/infra/config/node/kwild-config.tmpl @@ -74,7 +74,8 @@ compression = true [rpc] listen = '0.0.0.0:{{ default 8484 .RPC.Port }}' broadcast_tx_timeout = '{{ default "15s" .RPC.BroadcastTimeout }}' -timeout = '{{ default "20s" .RPC.RequestTimeout }}' +# 10s, not kwild's 20s: below the 15s timeout common in clients. It also caps broadcasts that wait for commit. +timeout = '{{ default "10s" .RPC.RequestTimeout }}' max_req_size = {{ default 6_000_000 .RPC.MaxReqSize }} private = {{ default false .RPC.Private }} compression = {{ default true .RPC.Compression }} diff --git a/deployments/infra/config/node/values.go b/deployments/infra/config/node/values.go index b8ed64368..5dd25cabe 100644 --- a/deployments/infra/config/node/values.go +++ b/deployments/infra/config/node/values.go @@ -147,10 +147,12 @@ func NewDefaultValues() Values { ReadTimeout: "45s", MaxConns: 60, }, + // RequestTimeout is 10s, not kwild's 20s: it stays below the 15s timeout + // common in clients, so a slow call is cut before they give up. RPC: RPCConfig{ Port: 8484, BroadcastTimeout: "15s", - RequestTimeout: "20s", + RequestTimeout: "10s", MaxReqSize: 6000000, Private: false, Compression: true, diff --git a/deployments/infra/config/node/values_test.go b/deployments/infra/config/node/values_test.go index 3661dc8c8..d4ebd7608 100644 --- a/deployments/infra/config/node/values_test.go +++ b/deployments/infra/config/node/values_test.go @@ -97,4 +97,10 @@ func TestRenderKwildConfigTemplate(t *testing.T) { require.True(t, ok, "DB section not found or not a map") // DB.port is quoted in template so will be string assert.Equal(t, fmt.Sprintf("%d", sampleValues.DB.Port), dbMap["port"], "DB port mismatch") + + // RPC is unset, so the template's own default applies. It must match NewDefaultValues. + rpcMap, ok := parsedData["rpc"].(map[string]interface{}) + require.True(t, ok, "RPC section not found or not a map") + assert.Equal(t, "10s", rpcMap["timeout"], "RPC timeout template default mismatch") + assert.Equal(t, "10s", NewDefaultValues().RPC.RequestTimeout, "RPC timeout default mismatch") } diff --git a/deployments/infra/lib/constructs/validator_set/node_test.go b/deployments/infra/lib/constructs/validator_set/node_test.go new file mode 100644 index 000000000..100df9aef --- /dev/null +++ b/deployments/infra/lib/constructs/validator_set/node_test.go @@ -0,0 +1,44 @@ +package validator_set + +import ( + "fmt" + "strings" + "testing" + + "github.com/BurntSushi/toml" + "github.com/aws/jsii-runtime-go" + "github.com/stretchr/testify/require" + + kwilnetwork "github.com/trufnetwork/node/infra/lib/kwil-network" + kwilnetworkpeer "github.com/trufnetwork/node/infra/lib/kwil-network/peer" +) + +// Each node's rendered config.toml caps a user RPC request at 10 s, below the +// 15 s timeout common in clients, so a slow call is cut before they give up. +func TestRenderedConfigCapsRPCTimeout(t *testing.T) { + keys := []kwilnetwork.NodeKeys{ + {KeyType: "secp256k1", PublicKeyHex: "02" + strings.Repeat("11", 32)}, + {KeyType: "secp256k1", PublicKeyHex: "03" + strings.Repeat("22", 32)}, + } + peers := make([]kwilnetworkpeer.TNPeer, len(keys)) + for i, key := range keys { + peers[i] = kwilnetworkpeer.TNPeer{ + NodeId: key.NodeId(), + Address: jsii.String(fmt.Sprintf("node-%d.test.sub", i+1)), + NodeHexAddress: key.PublicKeyHex, + } + } + + for i := range peers { + rendered := populateAndRenderValues(nil, i, &ValidatorSetProps{}, peers[i], peers, keys) + + var cfg struct { + RPC struct { + Timeout string `toml:"timeout"` + } `toml:"rpc"` + } + _, err := toml.Decode(rendered.String(), &cfg) + require.NoError(t, err) + require.Equal(t, "10s", cfg.RPC.Timeout, "node %d", i) + } +}