Skip to content

Commit

Permalink
Remove unused SC Param fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kpinter-iohk committed Sep 26, 2024
1 parent 6473577 commit eaea79e
Show file tree
Hide file tree
Showing 34 changed files with 53 additions and 350 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Changelog](https://keepachangelog.com/en/1.1.0).
* Removed `claim-v1` and `claim-v2` commands
* Removed `save-root`, `committee-hash`, `committee-handover` and `collect-garbage` commands
* Removed `init-checkpoint`, `init-fuel`, `save-checkpoint`, `cbor-update-committee-message`, `cbor-merkle-root-insertion-message`, `cbor-merkle-tree-entry`, `cbor-merkle-tree`, `cbor-combined-merkle-proof`, and `cbor-plain-aggregate-public-keys` commands
* Removed `--chainId`, `--threshold-numerator` and `--threshold-denominator`

## Fixed
* CLI now returns non-zero exit code on failure
Expand Down
14 changes: 0 additions & 14 deletions offchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,7 @@ file `$CWD/config.json` in the following format:

```json
"sidechainParameters": {
"chainId": 123,
"genesisUtxo": "3824c3a7c4437cc6ca4f893cd1519ae1dbe77862304e14d910ddc1f32de69b60#1",
"threshold": {
"numerator": 2,
"denominator": 3
},
"governanceAuthority": "4f2d6145e1700ad11dc074cad9f4194cc53b0dbab6bd25dfea6c501a"
},
"runtimeConfig": {
Expand All @@ -115,10 +110,7 @@ file `$CWD/config.json` in the following format:
This allows to shorten a CLI call from:
```
nix run .#pc-contracts-cli -- deregister \
--sidechain-id 123 \
--genesis-committee-hash-utxo 3824c3a7c4437cc6ca4f893cd1519ae1dbe77862304e14d910ddc1f32de69b60#1 \
--threshold-numerator 2 \
--threshold-denominator 3 \
--governance-authority 4f2d6145e1700ad11dc074cad9f4194cc53b0dbab6bd25dfea6c501c \
--network testnet \
--ogmios-host localhost \
Expand Down Expand Up @@ -563,16 +555,10 @@ nix run .#pc-contracts-cli -- utils sign schnorr-secp256k1 \
The result corresponds to `BlockProducerRegistrationMsg` type in the code.
Available options:
- `-i,--sidechain-id` \
Sidechain ID
- `-c,--genesis-committee-hash-utxo TX_ID#TX_IDX` \
Input UTxO to be spent with the first committee hash setup
- `-g,--governance-authority PUB_KEY_HASH` \
Public key hash of governance authority
- `--threshold-numerator INT` \
The numerator for the ratio of the threshold
- `--threshold-denominator INT` \
The denominator for the ratio of the threshold
- `--sidechain-public-key SIDECHAIN_PUB_KEY` \
Sidechain public key
- `--input-utxo TX_ID#TX_IDX` \
Expand Down
5 changes: 0 additions & 5 deletions offchain/config.example.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{
"sidechainParameters": {
"chainId": 123,
"genesisUtxo": "3824c3a7c4437cc6ca4f893cd1519ae1dbe77862304e14d910ddc1f32de69b60#1",
"threshold": {
"numerator": 2,
"denominator": 3
},
"governanceAuthority": "4f2d6145e1700ad11dc074cad9f4194cc53b0dbab6bd25dfea6c501a"
},
"runtimeConfig": {
Expand Down
23 changes: 3 additions & 20 deletions offchain/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,6 @@ main = do

-- Do some validation on the CLI options
-----------------------
let numerator = (unwrap scParams).thresholdNumerator
let denominator = (unwrap scParams).thresholdDenominator
unless (gcd numerator denominator == one) $ failWith
$ "Threshold numerator and denominator are not coprime.\n"
<> "Numerator: "
<> BigInt.toString numerator
<> "\nDenominator: "
<> BigInt.toString denominator

unless (numerator <= denominator) $ failWith
$ "Threshold numerator is greater than denominator.\n"
<> "Numerator: "
<> BigInt.toString numerator
<> "\nDenominator: "
<> BigInt.toString denominator

let
governance = Just $ MultiSig $ MultiSigGovParams
{ governanceMembers:
Expand All @@ -160,17 +144,16 @@ main = do

liftEffect $ case endpointResp of
Right resp -> printEndpointResp resp
Left e -> failWith $ show e
Left e -> do
log $ show e
exit 1

UtilsOptions opts -> do
endpointResp <- runUtilsEndpoint opts.utilsOptions
printEndpointResp endpointResp

CLIVersion -> log versionString

failWith :: String -> Effect Unit
failWith errStr = log errStr *> exit 1

-- | Reads configuration file from `./config.json`, then
-- | parses CLI arguments. CLI arguments override the config files.
getOptions :: Effect Options
Expand Down
7 changes: 1 addition & 6 deletions offchain/src/TrustlessSidechain/ConfigFile.purs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ import Type.Row (type (+))
optExample :: Config
optExample =
{ sidechainParameters: Just
{ chainId: Just 1
, genesisUtxo: Just $ TransactionInput
{ genesisUtxo: Just $ TransactionInput
{ transactionId:
( wrap $ unsafePartial $ fromJust $ fromBytes
( hexToByteArrayUnsafe
Expand All @@ -46,10 +45,6 @@ optExample =
)
, index: UInt.fromInt 2
}
, threshold: Just
{ numerator: 2
, denominator: 3
}
, governanceAuthority: Just $ hexToByteArrayUnsafe "123456789abcdef0"
}
, paymentSigningKeyFile: Just "/absolute/path/to/payment.skey"
Expand Down
13 changes: 2 additions & 11 deletions offchain/src/TrustlessSidechain/ConfigFile/Codecs.purs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Data.UInt as UInt
import TrustlessSidechain.Options.Types (Config)
import TrustlessSidechain.Utils.Codecs
( byteArrayCodec
, thresholdCodec
, transactionInputCodec
)
import TrustlessSidechain.Utils.Crypto
Expand All @@ -46,20 +45,12 @@ configCodec =
where
scParamsCodec ::
CA.JsonCodec
{ chainId :: Maybe Int
, genesisUtxo :: Maybe TransactionInput
, threshold ::
Maybe
{ denominator :: Int
, numerator :: Int
}
{ genesisUtxo :: Maybe TransactionInput
, governanceAuthority :: Maybe ByteArray
}
scParamsCodec =
( CAR.object "sidechainParameters"
{ chainId: CAC.maybe CA.int
, genesisUtxo: CAC.maybe transactionInputCodec
, threshold: CAC.maybe thresholdCodec
{ genesisUtxo: CAC.maybe transactionInputCodec
, governanceAuthority: CAC.maybe byteArrayCodec
}
)
Expand Down
22 changes: 0 additions & 22 deletions offchain/src/TrustlessSidechain/Options/Parsers.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ module TrustlessSidechain.Options.Parsers
, cborEncodedAddressParser
, committeeSignature
, currencySymbolParser
, denominator
, ecdsaSecp256k1PrivateKey
, ecdsaSecp256k1PublicKey
, epoch
, governanceAuthority
, mkCurrencySymbol
, numerator
, parsePubKeyAndSignature
, parsePubKeyBytesAndSignatureBytes
, parseAssetName
Expand Down Expand Up @@ -252,26 +250,6 @@ registeredCandidatesCount = eitherReader
Nothing -> Left "failed to parse int registered-candidates-count"
)

-- | Parse a numerator in the threshold.
numerator :: ReadM BigInt
numerator = eitherReader
( \str -> case BigInt.fromString str of
Just i
| i >= zero -> pure i
| otherwise -> Left "numerator must be non-negative"
Nothing -> Left "failed to parse int numerator"
)

-- | Parse a denominator in the threshold.
denominator :: ReadM BigInt
denominator = eitherReader
( \str -> case BigInt.fromString str of
Just i
| i > zero -> pure i
| otherwise -> Left "denominator must be positive"
Nothing -> Left "failed to parse int denominator"
)

-- | Parse an epoch.
epoch :: ReadM BigInt
epoch = eitherReader
Expand Down
43 changes: 1 addition & 42 deletions offchain/src/TrustlessSidechain/Options/Specs.purs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ import TrustlessSidechain.NativeTokenManagement.Types
import TrustlessSidechain.Options.Parsers
( bigInt
, byteArray
, denominator
, ecdsaSecp256k1PrivateKey
, governanceAuthority
, networkId
, numerator
, permissionedCandidateKeys
, registrationSidechainKeys
, schnorrSecp256k1PrivateKey
Expand Down Expand Up @@ -397,15 +395,6 @@ serverConfigSpec

sidechainParamsSpec :: Maybe Config -> Parser SidechainParams
sidechainParamsSpec maybeConfig = ado
chainId <- option int $ fold
[ short 'i'
, long "sidechain-id"
, metavar "1"
, help "Sidechain ID"
, maybe mempty value
(maybeConfig >>= _.sidechainParameters >>= _.chainId)
]

genesisUtxo <- option Parsers.transactionInput $ fold
[ short 'c'
, long "genesis-committee-hash-utxo"
Expand All @@ -429,40 +418,10 @@ sidechainParamsSpec maybeConfig = ado
)
)
]

{ thresholdNumerator, thresholdDenominator } <-
let
thresholdNumeratorDenominatorOption = ado
thresholdNumerator <- option numerator $ fold
[ long "threshold-numerator"
, metavar "INT"
, help "The numerator for the ratio of the threshold"
, maybe mempty value
$ map (BigInt.fromInt <<< _.numerator)
( maybeConfig >>= _.sidechainParameters >>=
_.threshold
)
]
thresholdDenominator <- option denominator $ fold
[ long "threshold-denominator"
, metavar "INT"
, help "The denominator for the ratio of the threshold"
, maybe mempty value
$ map (BigInt.fromInt <<< _.denominator)
( maybeConfig >>= _.sidechainParameters >>=
_.threshold
)
]
in { thresholdNumerator, thresholdDenominator }
in
thresholdNumeratorDenominatorOption
in
SidechainParams
{ chainId: BigInt.fromInt chainId
, genesisUtxo
{ genesisUtxo
, governanceAuthority
, thresholdNumerator
, thresholdDenominator
}

-- | SidechainParams CLI parser
Expand Down
8 changes: 1 addition & 7 deletions offchain/src/TrustlessSidechain/Options/Types.purs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,7 @@ type Config =
{ -- | Sidechain parameters (defining the sidechain which we will interact with)
sidechainParameters ::
Maybe
{ chainId :: Maybe Int
, genesisUtxo :: Maybe TransactionInput
, threshold ::
Maybe
{ numerator :: Int
, denominator :: Int
}
{ genesisUtxo :: Maybe TransactionInput
-- governanceAuthority should really be a PubKeyHash but there's no
-- (easy) way of pulling a dummy PubKeyHash value out of thin air in
-- TrustlessSidechain.ConfigFile.optExample
Expand Down
16 changes: 8 additions & 8 deletions offchain/src/TrustlessSidechain/RawScripts.purs

Large diffs are not rendered by default.

34 changes: 5 additions & 29 deletions offchain/src/TrustlessSidechain/SidechainParams.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,10 @@ import Contract.PlutusData
)
import Contract.Transaction (TransactionInput)
import Control.Alternative (guard)
import JS.BigInt (BigInt)
import TrustlessSidechain.Governance.Admin as Governance

newtype SidechainParams = SidechainParams
{ chainId :: BigInt
, genesisUtxo :: TransactionInput
,
-- `thresholdNumerator` is the numerator of the ratio required for the
-- committee to verify that committee has signed something (e.g. when
-- updating the committee hash, or saving a new merkle root).
thresholdNumerator :: BigInt
,
-- `thresholdDenominator` is the denominator of the ratio required for the
-- committee to verify that committee has signed something (e.g. when
-- updating the committee hash, or saving a new merkle root).
thresholdDenominator :: BigInt
{ genesisUtxo :: TransactionInput
, -- Governance mechanism. We temporarily rely on using a single master key
-- that can authorize any action requiring permission from the governing
-- committee.
Expand All @@ -43,35 +31,23 @@ derive newtype instance Eq SidechainParams
instance ToData SidechainParams where
toData
( SidechainParams
{ chainId
, genesisUtxo
, thresholdNumerator
, thresholdDenominator
{ genesisUtxo
, governanceAuthority
}
) =
Constr (BigNum.fromInt 0)
[ toData chainId
, toData genesisUtxo
, toData thresholdNumerator
, toData thresholdDenominator
[ toData genesisUtxo
, toData governanceAuthority
]

instance FromData SidechainParams where
fromData = case _ of
Constr ix [ cid, gu, tn, td, ga ] -> do
Constr ix [ gu, ga ] -> do
guard (ix == BigNum.fromInt 0)
chainId <- fromData cid
genesisUtxo <- fromData gu
thresholdNumerator <- fromData tn
thresholdDenominator <- fromData td
governanceAuthority <- fromData ga
pure $ SidechainParams
{ chainId
, genesisUtxo
, thresholdNumerator
, thresholdDenominator
{ genesisUtxo
, governanceAuthority
}
_ -> Nothing
Expand Down
Loading

0 comments on commit eaea79e

Please sign in to comment.