github.com/stellar/stellar-etl@v1.0.1-0.20240312145900-4874b6bf2b89/internal/transform/config_setting.go (about) 1 package transform 2 3 import ( 4 "fmt" 5 "strconv" 6 7 "github.com/stellar/go/ingest" 8 "github.com/stellar/go/xdr" 9 "github.com/stellar/stellar-etl/internal/utils" 10 ) 11 12 // TransformConfigSetting converts an config setting ledger change entry into a form suitable for BigQuery 13 func TransformConfigSetting(ledgerChange ingest.Change, header xdr.LedgerHeaderHistoryEntry) (ConfigSettingOutput, error) { 14 ledgerEntry, changeType, outputDeleted, err := utils.ExtractEntryFromChange(ledgerChange) 15 if err != nil { 16 return ConfigSettingOutput{}, err 17 } 18 19 configSetting, ok := ledgerEntry.Data.GetConfigSetting() 20 if !ok { 21 return ConfigSettingOutput{}, fmt.Errorf("Could not extract config setting from ledger entry; actual type is %s", ledgerEntry.Data.Type) 22 } 23 24 configSettingId := configSetting.ConfigSettingId 25 26 contractMaxSizeBytes, _ := configSetting.GetContractMaxSizeBytes() 27 28 contractCompute, _ := configSetting.GetContractCompute() 29 ledgerMaxInstructions := contractCompute.LedgerMaxInstructions 30 txMaxInstructions := contractCompute.TxMaxInstructions 31 feeRatePerInstructionsIncrement := contractCompute.FeeRatePerInstructionsIncrement 32 txMemoryLimit := contractCompute.TxMemoryLimit 33 34 contractLedgerCost, _ := configSetting.GetContractLedgerCost() 35 ledgerMaxReadLedgerEntries := contractLedgerCost.LedgerMaxReadLedgerEntries 36 ledgerMaxReadBytes := contractLedgerCost.LedgerMaxReadBytes 37 ledgerMaxWriteLedgerEntries := contractLedgerCost.LedgerMaxWriteLedgerEntries 38 ledgerMaxWriteBytes := contractLedgerCost.LedgerMaxWriteBytes 39 txMaxReadLedgerEntries := contractLedgerCost.TxMaxReadLedgerEntries 40 txMaxReadBytes := contractLedgerCost.TxMaxReadBytes 41 txMaxWriteLedgerEntries := contractLedgerCost.TxMaxWriteLedgerEntries 42 txMaxWriteBytes := contractLedgerCost.TxMaxWriteBytes 43 feeReadLedgerEntry := contractLedgerCost.FeeReadLedgerEntry 44 feeWriteLedgerEntry := contractLedgerCost.FeeWriteLedgerEntry 45 feeRead1Kb := contractLedgerCost.FeeRead1Kb 46 bucketListTargetSizeBytes := contractLedgerCost.BucketListTargetSizeBytes 47 writeFee1KbBucketListLow := contractLedgerCost.WriteFee1KbBucketListLow 48 writeFee1KbBucketListHigh := contractLedgerCost.WriteFee1KbBucketListHigh 49 bucketListWriteFeeGrowthFactor := contractLedgerCost.BucketListWriteFeeGrowthFactor 50 51 contractHistoricalData, ok := configSetting.GetContractHistoricalData() 52 feeHistorical1Kb := contractHistoricalData.FeeHistorical1Kb 53 54 contractMetaData, _ := configSetting.GetContractEvents() 55 txMaxContractEventsSizeBytes := contractMetaData.TxMaxContractEventsSizeBytes 56 feeContractEvents1Kb := contractMetaData.FeeContractEvents1Kb 57 58 contractBandwidth, _ := configSetting.GetContractBandwidth() 59 ledgerMaxTxsSizeBytes := contractBandwidth.LedgerMaxTxsSizeBytes 60 txMaxSizeBytes := contractBandwidth.TxMaxSizeBytes 61 feeTxSize1Kb := contractBandwidth.FeeTxSize1Kb 62 63 paramsCpuInsns, _ := configSetting.GetContractCostParamsCpuInsns() 64 contractCostParamsCpuInsns := serializeParams(paramsCpuInsns) 65 66 paramsMemBytes, _ := configSetting.GetContractCostParamsMemBytes() 67 contractCostParamsMemBytes := serializeParams(paramsMemBytes) 68 69 contractDataKeySizeBytes, ok := configSetting.GetContractDataKeySizeBytes() 70 71 contractDataEntrySizeBytes, ok := configSetting.GetContractDataEntrySizeBytes() 72 73 stateArchivalSettings, _ := configSetting.GetStateArchivalSettings() 74 maxEntryTtl := stateArchivalSettings.MaxEntryTtl 75 minTemporaryTtl := stateArchivalSettings.MinTemporaryTtl 76 minPersistentTtl := stateArchivalSettings.MinPersistentTtl 77 persistentRentRateDenominator := stateArchivalSettings.PersistentRentRateDenominator 78 tempRentRateDenominator := stateArchivalSettings.TempRentRateDenominator 79 maxEntriesToArchive := stateArchivalSettings.MaxEntriesToArchive 80 bucketListSizeWindowSampleSize := stateArchivalSettings.BucketListSizeWindowSampleSize 81 evictionScanSize := stateArchivalSettings.EvictionScanSize 82 startingEvictionScanLevel := stateArchivalSettings.StartingEvictionScanLevel 83 84 contractExecutionLanes, _ := configSetting.GetContractExecutionLanes() 85 ledgerMaxTxCount := contractExecutionLanes.LedgerMaxTxCount 86 87 bucketList, _ := configSetting.GetBucketListSizeWindow() 88 bucketListSizeWindow := make([]uint64, 0, len(bucketList)) 89 for _, sizeWindow := range bucketList { 90 bucketListSizeWindow = append(bucketListSizeWindow, uint64(sizeWindow)) 91 } 92 93 closedAt, err := utils.TimePointToUTCTimeStamp(header.Header.ScpValue.CloseTime) 94 if err != nil { 95 return ConfigSettingOutput{}, err 96 } 97 98 ledgerSequence := header.Header.LedgerSeq 99 100 transformedConfigSetting := ConfigSettingOutput{ 101 ConfigSettingId: int32(configSettingId), 102 ContractMaxSizeBytes: uint32(contractMaxSizeBytes), 103 LedgerMaxInstructions: int64(ledgerMaxInstructions), 104 TxMaxInstructions: int64(txMaxInstructions), 105 FeeRatePerInstructionsIncrement: int64(feeRatePerInstructionsIncrement), 106 TxMemoryLimit: uint32(txMemoryLimit), 107 LedgerMaxReadLedgerEntries: uint32(ledgerMaxReadLedgerEntries), 108 LedgerMaxReadBytes: uint32(ledgerMaxReadBytes), 109 LedgerMaxWriteLedgerEntries: uint32(ledgerMaxWriteLedgerEntries), 110 LedgerMaxWriteBytes: uint32(ledgerMaxWriteBytes), 111 TxMaxReadLedgerEntries: uint32(txMaxReadLedgerEntries), 112 TxMaxReadBytes: uint32(txMaxReadBytes), 113 TxMaxWriteLedgerEntries: uint32(txMaxWriteLedgerEntries), 114 TxMaxWriteBytes: uint32(txMaxWriteBytes), 115 FeeReadLedgerEntry: int64(feeReadLedgerEntry), 116 FeeWriteLedgerEntry: int64(feeWriteLedgerEntry), 117 FeeRead1Kb: int64(feeRead1Kb), 118 BucketListTargetSizeBytes: int64(bucketListTargetSizeBytes), 119 WriteFee1KbBucketListLow: int64(writeFee1KbBucketListLow), 120 WriteFee1KbBucketListHigh: int64(writeFee1KbBucketListHigh), 121 BucketListWriteFeeGrowthFactor: uint32(bucketListWriteFeeGrowthFactor), 122 FeeHistorical1Kb: int64(feeHistorical1Kb), 123 TxMaxContractEventsSizeBytes: uint32(txMaxContractEventsSizeBytes), 124 FeeContractEvents1Kb: int64(feeContractEvents1Kb), 125 LedgerMaxTxsSizeBytes: uint32(ledgerMaxTxsSizeBytes), 126 TxMaxSizeBytes: uint32(txMaxSizeBytes), 127 FeeTxSize1Kb: int64(feeTxSize1Kb), 128 ContractCostParamsCpuInsns: contractCostParamsCpuInsns, 129 ContractCostParamsMemBytes: contractCostParamsMemBytes, 130 ContractDataKeySizeBytes: uint32(contractDataKeySizeBytes), 131 ContractDataEntrySizeBytes: uint32(contractDataEntrySizeBytes), 132 MaxEntryTtl: uint32(maxEntryTtl), 133 MinTemporaryTtl: uint32(minTemporaryTtl), 134 MinPersistentTtl: uint32(minPersistentTtl), 135 PersistentRentRateDenominator: int64(persistentRentRateDenominator), 136 TempRentRateDenominator: int64(tempRentRateDenominator), 137 MaxEntriesToArchive: uint32(maxEntriesToArchive), 138 BucketListSizeWindowSampleSize: uint32(bucketListSizeWindowSampleSize), 139 EvictionScanSize: uint64(evictionScanSize), 140 StartingEvictionScanLevel: uint32(startingEvictionScanLevel), 141 LedgerMaxTxCount: uint32(ledgerMaxTxCount), 142 BucketListSizeWindow: bucketListSizeWindow, 143 LastModifiedLedger: uint32(ledgerEntry.LastModifiedLedgerSeq), 144 LedgerEntryChange: uint32(changeType), 145 Deleted: outputDeleted, 146 ClosedAt: closedAt, 147 LedgerSequence: uint32(ledgerSequence), 148 } 149 return transformedConfigSetting, nil 150 } 151 152 func serializeParams(costParams xdr.ContractCostParams) []map[string]string { 153 params := make([]map[string]string, 0, len(costParams)) 154 for _, contractCostParam := range costParams { 155 serializedParam := map[string]string{} 156 serializedParam["ExtV"] = strconv.Itoa(int(contractCostParam.Ext.V)) 157 serializedParam["ConstTerm"] = strconv.Itoa(int(contractCostParam.ConstTerm)) 158 serializedParam["LinearTerm"] = strconv.Itoa(int(contractCostParam.LinearTerm)) 159 params = append(params, serializedParam) 160 } 161 162 return params 163 }