Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions deployments/infra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion deployments/infra/config/node/kwild-config.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 3 additions & 1 deletion deployments/infra/config/node/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions deployments/infra/config/node/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
44 changes: 44 additions & 0 deletions deployments/infra/lib/constructs/validator_set/node_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading