babylonchain / finality-provider

A peripheral program run by the finality providers
Other
16 stars 27 forks source link

improve interface `QueryLastCommittedPublicRand()` #407

Closed bap2pecs closed 3 months ago

bap2pecs commented 3 months ago
    QueryLastCommittedPublicRand(fpPk *btcec.PublicKey, count uint64) (map[uint64]*types.PubRandCommit, error)

it will always pass in count 1

and the return value shouldn't be a map because it will never have two keys in the map

for now it will always return a single-value map like this:

{
   "122881": {"num_pub_rand": 64, "commitment": <hash>}
}

so I'd suggest we remove the count and simplify the return type

lesterli commented 3 months ago

Indeed, we should consider refactoring if it will never have two keys on the map. b/c it is inconvenient to use, the codes would be like this:

    // query pub rand
    committedPubRandMap, err := ctm.OpL2ConsumerCtrl.QueryLastCommittedPublicRand(fpInstance.GetBtcPk(), 1)
    require.NoError(t, err)
    var lastCommittedHeight uint64
    for key := range committedPubRandMap {
        lastCommittedHeight = key
        break
    }
SebastianElvis commented 3 months ago

Sounds good to me :+1: