Skip to content

Commit 2da660c

Browse files
committed
Add offchain_vote_data config flag, default disabled for pools and votes
1 parent 887fd73 commit 2da660c

9 files changed

Lines changed: 96 additions & 12 deletions

File tree

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Alonzo/Config.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ insertConfig = do
3131
, sioPlutus = PlutusDisable
3232
, sioGovernance = GovernanceConfig False
3333
, sioOffchainPoolData = OffchainPoolDataConfig False
34+
, sioOffchainVoteData = OffchainVoteDataConfig False
3435
, sioPoolStats = PoolStatsConfig False
3536
, sioJsonType = JsonTypeDisable
3637
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Config/Parse.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ insertConfig = do
8787
, sioPlutus = PlutusDisable
8888
, sioGovernance = GovernanceConfig False
8989
, sioOffchainPoolData = OffchainPoolDataConfig False
90+
, sioOffchainVoteData = OffchainVoteDataConfig False
9091
, sioPoolStats = PoolStatsConfig False
9192
, sioJsonType = JsonTypeDisable
9293
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False

cardano-db-sync/src/Cardano/DbSync.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ extractSyncOptions snp aop snc =
317317
, ioKeepMetadataNames = maybeKeepMNames
318318
, ioPlutusExtra = isPlutusEnabled (sioPlutus (dncInsertOptions snc))
319319
, ioOffChainPoolData = useOffchainPoolData
320+
, ioOffChainVoteData = useOffchainVoteData
320321
, ioPoolStats = isPoolStatsEnabled (sioPoolStats (dncInsertOptions snc))
321322
, ioGov = useGovernance
322323
, ioRemoveJsonbFromSchema = isRemoveJsonbFromSchemaEnabled (sioRemoveJsonbFromSchema (dncInsertOptions snc))
@@ -326,6 +327,8 @@ extractSyncOptions snp aop snc =
326327
useLedger = sioLedger (dncInsertOptions snc) == LedgerEnable
327328
useOffchainPoolData =
328329
isOffchainPoolDataEnabled (sioOffchainPoolData (dncInsertOptions snc))
330+
useOffchainVoteData =
331+
isOffchainVoteDataEnabled (sioOffchainVoteData (dncInsertOptions snc))
329332
useGovernance =
330333
isGovernanceEnabled (sioGovernance (dncInsertOptions snc))
331334

cardano-db-sync/src/Cardano/DbSync/Api/Types.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ data InsertOptions = InsertOptions
8585
, ioKeepMetadataNames :: Strict.Maybe [Word64]
8686
, ioPlutusExtra :: !Bool
8787
, ioOffChainPoolData :: !Bool
88+
, ioOffChainVoteData :: !Bool
8889
, ioPoolStats :: !Bool
8990
, ioGov :: !Bool
9091
, ioRemoveJsonbFromSchema :: !Bool

cardano-db-sync/src/Cardano/DbSync/Config/Types.hs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module Cardano.DbSync.Config.Types (
3838
PlutusConfig (..),
3939
GovernanceConfig (..),
4040
OffchainPoolDataConfig (..),
41+
OffchainVoteDataConfig (..),
4142
JsonTypeConfig (..),
4243
SnapshotIntervalConfig (..),
4344
LedgerStateDir (..),
@@ -189,6 +190,7 @@ data SyncInsertOptions = SyncInsertOptions
189190
, sioPlutus :: PlutusConfig
190191
, sioGovernance :: GovernanceConfig
191192
, sioOffchainPoolData :: OffchainPoolDataConfig
193+
, sioOffchainVoteData :: OffchainVoteDataConfig
192194
, sioPoolStats :: PoolStatsConfig
193195
, sioJsonType :: JsonTypeConfig
194196
, sioRemoveJsonbFromSchema :: RemoveJsonbFromSchemaConfig
@@ -266,6 +268,11 @@ newtype OffchainPoolDataConfig = OffchainPoolDataConfig
266268
}
267269
deriving (Eq, Show)
268270

271+
newtype OffchainVoteDataConfig = OffchainVoteDataConfig
272+
{ isOffchainVoteDataEnabled :: Bool
273+
}
274+
deriving (Eq, Show)
275+
269276
newtype RemoveJsonbFromSchemaConfig = RemoveJsonbFromSchemaConfig
270277
{ isRemoveJsonbFromSchemaEnabled :: Bool
271278
}
@@ -462,6 +469,7 @@ parseOverrides obj baseOptions = do
462469
<*> obj .:? "plutus" .!= sioPlutus baseOptions
463470
<*> obj .:? "governance" .!= sioGovernance baseOptions
464471
<*> obj .:? "offchain_pool_data" .!= sioOffchainPoolData baseOptions
472+
<*> obj .:? "offchain_vote_data" .!= sioOffchainVoteData baseOptions
465473
<*> obj .:? "pool_stat" .!= sioPoolStats baseOptions
466474
<*> obj .:? "json_type" .!= sioJsonType baseOptions
467475
<*> obj .:? "remove_jsonb_from_schema" .!= sioRemoveJsonbFromSchema baseOptions
@@ -484,6 +492,7 @@ optionsToList SyncInsertOptions {..} =
484492
, toJsonIfSet "plutus" sioPlutus
485493
, toJsonIfSet "governance" sioGovernance
486494
, toJsonIfSet "offchain_pool_data" sioOffchainPoolData
495+
, toJsonIfSet "offchain_vote_data" sioOffchainVoteData
487496
, toJsonIfSet "pool_stat" sioPoolStats
488497
, toJsonIfSet "json_type" sioJsonType
489498
, toJsonIfSet "remove_jsonb_from_schema" sioRemoveJsonbFromSchema
@@ -506,6 +515,7 @@ instance FromJSON SyncInsertOptions where
506515
<*> obj .:? "plutus" .!= sioPlutus def
507516
<*> obj .:? "governance" .!= sioGovernance def
508517
<*> obj .:? "offchain_pool_data" .!= sioOffchainPoolData def
518+
<*> obj .:? "offchain_vote_data" .!= sioOffchainVoteData def
509519
<*> obj .:? "pool_stat" .!= sioPoolStats def
510520
<*> obj .:? "json_type" .!= sioJsonType def
511521
<*> obj .:? "remove_jsonb_from_schema" .!= sioRemoveJsonbFromSchema def
@@ -523,6 +533,7 @@ instance ToJSON SyncInsertOptions where
523533
, "plutus" .= sioPlutus
524534
, "governance" .= sioGovernance
525535
, "offchain_pool_data" .= sioOffchainPoolData
536+
, "offchain_vote_data" .= sioOffchainVoteData
526537
, "pool_stat" .= sioPoolStats
527538
, "json_type" .= sioJsonType
528539
, "remove_jsonb_from_schema" .= sioRemoveJsonbFromSchema
@@ -725,6 +736,15 @@ instance FromJSON OffchainPoolDataConfig where
725736
Just g -> pure (OffchainPoolDataConfig g)
726737
Nothing -> fail $ "unexpected offchain_pool_data: " <> show v
727738

739+
instance ToJSON OffchainVoteDataConfig where
740+
toJSON = boolToEnableDisable . isOffchainVoteDataEnabled
741+
742+
instance FromJSON OffchainVoteDataConfig where
743+
parseJSON = Aeson.withText "offchain_vote_data" $ \v ->
744+
case enableDisableToBool v of
745+
Just g -> pure (OffchainVoteDataConfig g)
746+
Nothing -> fail $ "unexpected offchain_vote_data: " <> show v
747+
728748
instance ToJSON JsonTypeConfig where
729749
toJSON JsonTypeText = "text"
730750
toJSON JsonTypeJsonb = "jsonb"
@@ -769,7 +789,8 @@ instance Default SyncInsertOptions where
769789
, sioMetadata = MetadataEnable
770790
, sioPlutus = PlutusEnable
771791
, sioGovernance = GovernanceConfig True
772-
, sioOffchainPoolData = OffchainPoolDataConfig True
792+
, sioOffchainPoolData = OffchainPoolDataConfig False
793+
, sioOffchainVoteData = OffchainVoteDataConfig False
773794
, sioPoolStats = PoolStatsConfig False
774795
, sioJsonType = JsonTypeText
775796
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
@@ -788,7 +809,8 @@ fullInsertOptions =
788809
, sioMetadata = MetadataEnable
789810
, sioPlutus = PlutusEnable
790811
, sioGovernance = GovernanceConfig True
791-
, sioOffchainPoolData = OffchainPoolDataConfig True
812+
, sioOffchainPoolData = OffchainPoolDataConfig False
813+
, sioOffchainVoteData = OffchainVoteDataConfig False
792814
, sioPoolStats = PoolStatsConfig True
793815
, sioJsonType = JsonTypeText
794816
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
@@ -806,8 +828,9 @@ onlyUTxOInsertOptions =
806828
, sioMultiAsset = MultiAssetEnable
807829
, sioMetadata = MetadataDisable
808830
, sioPlutus = PlutusDisable
809-
, sioGovernance = GovernanceConfig False
831+
, sioGovernance = GovernanceConfig True
810832
, sioOffchainPoolData = OffchainPoolDataConfig False
833+
, sioOffchainVoteData = OffchainVoteDataConfig False
811834
, sioPoolStats = PoolStatsConfig False
812835
, sioJsonType = JsonTypeText
813836
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
@@ -834,6 +857,7 @@ disableAllInsertOptions =
834857
, sioMetadata = MetadataDisable
835858
, sioPlutus = PlutusDisable
836859
, sioOffchainPoolData = OffchainPoolDataConfig False
860+
, sioOffchainVoteData = OffchainVoteDataConfig False
837861
, sioPoolStats = PoolStatsConfig False
838862
, sioGovernance = GovernanceConfig False
839863
, sioJsonType = JsonTypeText

cardano-db-sync/src/Cardano/DbSync/OffChain.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ runFetchOffChainPoolThread syncEnv = do
268268
runFetchOffChainVoteThread :: SyncEnv -> IO ()
269269
runFetchOffChainVoteThread syncEnv = do
270270
-- if disable gov is active then don't run voting anchor thread
271-
when (ioGov iopts) $ do
271+
when (ioOffChainVoteData iopts && ioGov iopts) $ do
272272
logInfo trce "Running Offchain Vote Anchor fetch thread"
273273
pgconfig <- DB.runOrThrowIO (DB.readPGPass DB.PGPassDefaultEnv)
274274
connSetting <- case DB.toConnectionSetting pgconfig of

cardano-db-sync/test/Cardano/DbSync/Config/TypesTest.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ genDefaultJson =
139139
"script_hashes": null
140140
},
141141
"governance": "enable",
142-
"offchain_pool_data": "enable",
142+
"offchain_pool_data": "disable",
143143
"json_type": "text"
144144
}
145145
|]
@@ -166,7 +166,7 @@ genDefaultJson =
166166
"enable": true
167167
},
168168
"governance": "enable",
169-
"offchain_pool_data": "enable",
169+
"offchain_pool_data": "disable",
170170
"json_type": "text"
171171
}
172172
|]

cardano-db-sync/test/Cardano/DbSync/Gen.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ syncInsertOptions =
132132
<*> plutusConfig
133133
<*> (GovernanceConfig <$> Gen.bool)
134134
<*> (OffchainPoolDataConfig <$> Gen.bool)
135+
<*> (OffchainVoteDataConfig <$> Gen.bool)
135136
<*> (PoolStatsConfig <$> Gen.bool)
136137
<*> Gen.element [JsonTypeText, JsonTypeJsonb, JsonTypeDisable]
137138
<*> (RemoveJsonbFromSchemaConfig <$> Gen.bool)

doc/configuration.md

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ file (`db-sync-config.json` or `db-sync-config.yaml`).
1616

1717
## Simple Example
1818

19-
Below is a sample `insert_options` section that shows all the defaults:
19+
Below is a sample `insert_options` section that shows the recommended defaults:
2020

2121
```
2222
{
@@ -41,12 +41,15 @@ Below is a sample `insert_options` section that shows all the defaults:
4141
"enable": true
4242
},
4343
"governance": "enable",
44-
"offchain_pool_data": "enable",
44+
"offchain_pool_data": "disable",
45+
"offchain_vote_data": "disable",
4546
"json_type": "text"
4647
}
4748
}
4849
```
4950

51+
**Note**: Starting from version 13.7.0.1, `offchain_pool_data` and `offchain_vote_data` default to `"disable"`. Enable them if you need offchain metadata fetching.
52+
5053
# Properties
5154

5255
`insert_options` may contain the following elements:
@@ -63,6 +66,7 @@ Below is a sample `insert_options` section that shows all the defaults:
6366
| [plutus](#plutus) | `object` | Optional |
6467
| [governance](#governance) | `enum` | Optional |
6568
| [offchain\_pool\_data](#offchain-pool-data) | `enum` | Optional |
69+
| [offchain\_vote\_data](#offchain-vote-data) | `enum` | Optional |
6670
| [pool\_stat](#pool-stat) | `enum` | Optional |
6771
| [remove\_jsonb_from_schema](#remove-jsonb-from-schema) | `enum` | Optional |
6872
| [stop\_at\_block](#stop-at-block) | `integer` | Optional |
@@ -113,7 +117,8 @@ This is equivalent to setting:
113117
"enable": false
114118
},
115119
"governance": "disable",
116-
"offchain_pool_data": "disable"
120+
"offchain_pool_data": "disable",
121+
"offchain_vote_data": "disable",
117122
"pool_stat": "disable"
118123
```
119124

@@ -142,7 +147,8 @@ This is equivalent to setting:
142147
"enable": false
143148
},
144149
"governance": "enable",
145-
"offchain_pool_data": "disable"
150+
"offchain_pool_data": "disable",
151+
"offchain_vote_data": "disable",
146152
"pool_stat": "enable"
147153
148154
```
@@ -170,7 +176,8 @@ This is equivalent to setting:
170176
"enable": false
171177
},
172178
"governance": "disable",
173-
"offchain_pool_data": "disable"
179+
"offchain_pool_data": "disable",
180+
"offchain_vote_data": "disable",
174181
"pool_stat": "disable"
175182
```
176183

@@ -532,9 +539,55 @@ This will effect all governance related data/functionality.
532539

533540
| Value | Explanation |
534541
| :--------- | :---------------------------------------- |
535-
| `"enable"` | Enables fetching offchain metadata. |
542+
| `"enable"` | Enables fetching offchain pool metadata. |
536543
| `"disable"`| Disables fetching pool offchain metadata. |
537544

545+
Controls whether db-sync fetches offchain metadata for stake pools. This metadata includes pool descriptions, ticker symbols, homepages, and other information referenced in pool registrations.
546+
547+
**Important**: Starting from version 13.7.0.1, this defaults to `"disable"`. Explicitly enable it if you need pool metadata.
548+
549+
When enabled, db-sync fetches metadata from URLs stored on-chain with the following restrictions:
550+
- HTTPS URLs required (HTTP allowed only for localhost testing)
551+
- Private/internal IP addresses blocked (RFC1918, loopback, link-local, IPv6 ULA)
552+
- DNS resolution performed immediately before requests
553+
554+
## Offchain Vote Data
555+
556+
`offchain_vote_data`
557+
558+
* Type: `string`
559+
560+
**enum**: The value of this property must be equal to one of the following values:
561+
562+
| Value | Explanation |
563+
| :--------- | :----------------------------------------------- |
564+
| `"enable"` | Enables fetching offchain governance vote metadata. |
565+
| `"disable"`| Disables fetching governance vote metadata. |
566+
567+
Controls whether db-sync fetches offchain metadata for governance voting anchors, including:
568+
- DRep registrations (CIP-119)
569+
- Governance action proposals (CIP-108)
570+
- Vote anchors and references (CIP-100)
571+
572+
This setting is independent of the `governance` flag, allowing granular control over general governance data versus offchain metadata fetching.
573+
574+
**Important**: Starting from version 13.7.0.1, this defaults to `"disable"`. Explicitly enable it if you need governance vote metadata.
575+
576+
When enabled, the same URL restrictions apply as `offchain_pool_data` (HTTPS required, private IPs blocked, immediate DNS resolution).
577+
578+
### Example
579+
580+
```json
581+
{
582+
"insert_options": {
583+
"governance": "enable",
584+
"offchain_vote_data": "enable"
585+
}
586+
}
587+
```
588+
589+
**Migration Note**: Prior to version 13.7.0.1, governance vote metadata fetching was controlled by the `governance` flag.
590+
538591
## Pool Stat
539592

540593
`pool_stat`

0 commit comments

Comments
 (0)