@@ -1071,6 +1071,28 @@ func (cfg *MempoolConfig) ValidateBasic() error {
10711071//-----------------------------------------------------------------------------
10721072// StateSyncConfig
10731073
1074+ // stateSyncTrustPeriods maps a well-known chain ID to its state sync trust period.
1075+ var stateSyncTrustPeriods = map [string ]time.Duration {
1076+ // A trust period plus the time needed to check headers and to report and
1077+ // punish misbehavior must stay below the network's unbonding time.
1078+ "pacific-1" : 112 * time .Hour ,
1079+ "atlantic-2" : 112 * time .Hour ,
1080+ "arctic-1" : 112 * time .Hour ,
1081+ }
1082+
1083+ // defaultStateSyncTrustPeriod is the state sync trust period of a chain that
1084+ // stateSyncTrustPeriods does not list.
1085+ const defaultStateSyncTrustPeriod = 168 * time .Hour
1086+
1087+ // StateSyncTrustPeriod returns how long after its time a header of chainID can
1088+ // still serve as the trusted root state sync verifies light blocks from.
1089+ func StateSyncTrustPeriod (chainID string ) time.Duration {
1090+ if trustPeriod , ok := stateSyncTrustPeriods [chainID ]; ok {
1091+ return trustPeriod
1092+ }
1093+ return defaultStateSyncTrustPeriod
1094+ }
1095+
10741096// StateSyncConfig defines the configuration for the Tendermint state sync service
10751097type StateSyncConfig struct {
10761098 // State sync rapidly bootstraps a new node by discovering, fetching, and restoring a
@@ -1090,15 +1112,11 @@ type StateSyncConfig struct {
10901112 // with net.Dial, for example: "host.example.com:2125".
10911113 RPCServers []string `mapstructure:"rpc-servers"`
10921114
1093- // The hash and height of a trusted block. Must be within the trust-period.
1115+ // The hash and height of a trusted block. Must be within the trust period
1116+ // StateSyncTrustPeriod returns for the chain.
10941117 TrustHeight int64 `mapstructure:"trust-height"`
10951118 TrustHash string `mapstructure:"trust-hash"`
10961119
1097- // The trust period should be set so that Tendermint can detect and gossip
1098- // misbehavior before it is considered expired. For chains based on the Cosmos SDK,
1099- // one day less than the unbonding period should suffice.
1100- TrustPeriod time.Duration `mapstructure:"trust-period"`
1101-
11021120 // Backfill sequentially fetches, verifies and stores light blocks in reverse order.
11031121 // It does not stop verifying blocks until reaching a height
11041122 // that is less or equal to the latestBlock - backfill-blocks and latest block time - backfill-duration.
@@ -1149,7 +1167,6 @@ func (cfg *StateSyncConfig) TrustHashBytes() []byte {
11491167// DefaultStateSyncConfig returns a default configuration for the state sync service
11501168func DefaultStateSyncConfig () * StateSyncConfig {
11511169 return & StateSyncConfig {
1152- TrustPeriod : 168 * time .Hour ,
11531170 DiscoveryTime : 15 * time .Second ,
11541171 ChunkRequestTimeout : 15 * time .Second ,
11551172 Fetchers : 2 ,
@@ -1190,10 +1207,6 @@ func (cfg *StateSyncConfig) ValidateBasic() error {
11901207 return errors .New ("discovery time must be 0s or greater than five seconds" )
11911208 }
11921209
1193- if cfg .TrustPeriod <= 0 {
1194- return errors .New ("trusted-period is required" )
1195- }
1196-
11971210 if cfg .TrustHeight <= 0 {
11981211 return errors .New ("trusted-height is required" )
11991212 }
0 commit comments