@@ -3,7 +3,6 @@ package protocol
33import (
44 "fmt"
55 "math/big"
6- "sync"
76 "time"
87
98 "github.com/ethereum/go-ethereum/accounts/abi/bind"
@@ -17,134 +16,124 @@ import (
1716
1817// Config
1918const (
20- PerformanceSettingsContractName string = "rocketDAOProtocolSettingsPerformance"
21- PerformanceExitsEnabledSettingPath string = "performance.exits.enabled"
22- PerformancePeriodSettingPath string = "performance.period"
23- ProofBufferSettingPath string = "proof.buffer"
24- PerformanceThresholdSettingPath string = "performance.threshold"
25- PerformanceChallengePeriodSettingPath string = "performance.challenge.period"
26- PerformanceChallengeBondSettingPath string = "performance.challenge.bond"
19+ PerformanceExitsEnabledSettingPath string = "network.performance.exits.enabled"
20+ PerformancePeriodSettingPath string = "network.performance.period"
21+ ProofBufferSettingPath string = "network.performance.proof.buffer"
22+ PerformanceThresholdSettingPath string = "network.performance.threshold"
23+ PerformanceChallengePeriodSettingPath string = "network.performance.challenge.period"
24+ PerformanceChallengeBondSettingPath string = "network.performance.challenge.bond"
2725)
2826
2927// Performance exits currently enabled
3028func GetPerformanceExitsEnabled (rp * rocketpool.RocketPool , opts * bind.CallOpts ) (bool , error ) {
31- performanceSettingsContract , err := getPerformanceSettingsContract (rp , opts )
29+ networkSettingsContract , err := getNetworkSettingsContract (rp , opts )
3230 if err != nil {
3331 return false , err
3432 }
3533 value := new (bool )
36- if err := performanceSettingsContract .Call (opts , value , "getPerformanceExitsEnabled" ); err != nil {
34+ if err := networkSettingsContract .Call (opts , value , "getPerformanceExitsEnabled" ); err != nil {
3735 return false , fmt .Errorf ("error getting performance exits enabled status: %w" , err )
3836 }
3937 return * value , nil
4038}
4139func ProposePerformanceExitsEnabled (rp * rocketpool.RocketPool , value bool , blockNumber uint32 , treeNodes []types.VotingTreeNode , opts * bind.TransactOpts ) (uint64 , common.Hash , error ) {
42- return protocol .ProposeSetBool (rp , fmt .Sprintf ("set %s" , PerformanceExitsEnabledSettingPath ), PerformanceSettingsContractName , PerformanceExitsEnabledSettingPath , value , blockNumber , treeNodes , opts )
40+ return protocol .ProposeSetBool (rp , fmt .Sprintf ("set %s" , PerformanceExitsEnabledSettingPath ), NetworkSettingsContractName , PerformanceExitsEnabledSettingPath , value , blockNumber , treeNodes , opts )
4341}
4442func EstimateProposePerformanceExitsEnabledGas (rp * rocketpool.RocketPool , value bool , blockNumber uint32 , treeNodes []types.VotingTreeNode , opts * bind.TransactOpts ) (gaslimit.Limits , error ) {
45- return protocol .EstimateProposeSetBoolGas (rp , fmt .Sprintf ("set %s" , PerformanceExitsEnabledSettingPath ), PerformanceSettingsContractName , PerformanceExitsEnabledSettingPath , value , blockNumber , treeNodes , opts )
43+ return protocol .EstimateProposeSetBoolGas (rp , fmt .Sprintf ("set %s" , PerformanceExitsEnabledSettingPath ), NetworkSettingsContractName , PerformanceExitsEnabledSettingPath , value , blockNumber , treeNodes , opts )
4644}
4745
4846// Number of epochs over which attestation performance is measured
4947func GetPerformancePeriod (rp * rocketpool.RocketPool , opts * bind.CallOpts ) (uint64 , error ) {
50- performanceSettingsContract , err := getPerformanceSettingsContract (rp , opts )
48+ networkSettingsContract , err := getNetworkSettingsContract (rp , opts )
5149 if err != nil {
5250 return 0 , err
5351 }
5452 value := new (* big.Int )
55- if err := performanceSettingsContract .Call (opts , value , "getPerformancePeriod" ); err != nil {
53+ if err := networkSettingsContract .Call (opts , value , "getPerformancePeriod" ); err != nil {
5654 return 0 , fmt .Errorf ("error getting performance period: %w" , err )
5755 }
5856 return (* value ).Uint64 (), nil
5957}
6058func ProposePerformancePeriod (rp * rocketpool.RocketPool , value * big.Int , blockNumber uint32 , treeNodes []types.VotingTreeNode , opts * bind.TransactOpts ) (uint64 , common.Hash , error ) {
61- return protocol .ProposeSetUint (rp , fmt .Sprintf ("set %s" , PerformancePeriodSettingPath ), PerformanceSettingsContractName , PerformancePeriodSettingPath , value , blockNumber , treeNodes , opts )
59+ return protocol .ProposeSetUint (rp , fmt .Sprintf ("set %s" , PerformancePeriodSettingPath ), NetworkSettingsContractName , PerformancePeriodSettingPath , value , blockNumber , treeNodes , opts )
6260}
6361func EstimateProposePerformancePeriodGas (rp * rocketpool.RocketPool , value * big.Int , blockNumber uint32 , treeNodes []types.VotingTreeNode , opts * bind.TransactOpts ) (gaslimit.Limits , error ) {
64- return protocol .EstimateProposeSetUintGas (rp , fmt .Sprintf ("set %s" , PerformancePeriodSettingPath ), PerformanceSettingsContractName , PerformancePeriodSettingPath , value , blockNumber , treeNodes , opts )
62+ return protocol .EstimateProposeSetUintGas (rp , fmt .Sprintf ("set %s" , PerformancePeriodSettingPath ), NetworkSettingsContractName , PerformancePeriodSettingPath , value , blockNumber , treeNodes , opts )
6563}
6664
6765// Buffer to detect underperformance and generate proofs before a validator can be challenged (epochs)
6866func GetProofBuffer (rp * rocketpool.RocketPool , opts * bind.CallOpts ) (uint64 , error ) {
69- performanceSettingsContract , err := getPerformanceSettingsContract (rp , opts )
67+ networkSettingsContract , err := getNetworkSettingsContract (rp , opts )
7068 if err != nil {
7169 return 0 , err
7270 }
7371 value := new (* big.Int )
74- if err := performanceSettingsContract .Call (opts , value , "getProofBuffer " ); err != nil {
72+ if err := networkSettingsContract .Call (opts , value , "getPerformanceProofBuffer " ); err != nil {
7573 return 0 , fmt .Errorf ("error getting proof buffer: %w" , err )
7674 }
7775 return (* value ).Uint64 (), nil
7876}
7977func ProposeProofBuffer (rp * rocketpool.RocketPool , value * big.Int , blockNumber uint32 , treeNodes []types.VotingTreeNode , opts * bind.TransactOpts ) (uint64 , common.Hash , error ) {
80- return protocol .ProposeSetUint (rp , fmt .Sprintf ("set %s" , ProofBufferSettingPath ), PerformanceSettingsContractName , ProofBufferSettingPath , value , blockNumber , treeNodes , opts )
78+ return protocol .ProposeSetUint (rp , fmt .Sprintf ("set %s" , ProofBufferSettingPath ), NetworkSettingsContractName , ProofBufferSettingPath , value , blockNumber , treeNodes , opts )
8179}
8280func EstimateProposeProofBufferGas (rp * rocketpool.RocketPool , value * big.Int , blockNumber uint32 , treeNodes []types.VotingTreeNode , opts * bind.TransactOpts ) (gaslimit.Limits , error ) {
83- return protocol .EstimateProposeSetUintGas (rp , fmt .Sprintf ("set %s" , ProofBufferSettingPath ), PerformanceSettingsContractName , ProofBufferSettingPath , value , blockNumber , treeNodes , opts )
81+ return protocol .EstimateProposeSetUintGas (rp , fmt .Sprintf ("set %s" , ProofBufferSettingPath ), NetworkSettingsContractName , ProofBufferSettingPath , value , blockNumber , treeNodes , opts )
8482}
8583
8684// Minimum target attestation timeliness percentage required to avoid exit
8785func GetPerformanceThreshold (rp * rocketpool.RocketPool , opts * bind.CallOpts ) (* big.Int , error ) {
88- performanceSettingsContract , err := getPerformanceSettingsContract (rp , opts )
86+ networkSettingsContract , err := getNetworkSettingsContract (rp , opts )
8987 if err != nil {
9088 return nil , err
9189 }
9290 value := new (* big.Int )
93- if err := performanceSettingsContract .Call (opts , value , "getPerformanceThreshold" ); err != nil {
91+ if err := networkSettingsContract .Call (opts , value , "getPerformanceThreshold" ); err != nil {
9492 return nil , fmt .Errorf ("error getting performance threshold: %w" , err )
9593 }
9694 return * value , nil
9795}
9896func ProposePerformanceThreshold (rp * rocketpool.RocketPool , value * big.Int , blockNumber uint32 , treeNodes []types.VotingTreeNode , opts * bind.TransactOpts ) (uint64 , common.Hash , error ) {
99- return protocol .ProposeSetUint (rp , fmt .Sprintf ("set %s" , PerformanceThresholdSettingPath ), PerformanceSettingsContractName , PerformanceThresholdSettingPath , value , blockNumber , treeNodes , opts )
97+ return protocol .ProposeSetUint (rp , fmt .Sprintf ("set %s" , PerformanceThresholdSettingPath ), NetworkSettingsContractName , PerformanceThresholdSettingPath , value , blockNumber , treeNodes , opts )
10098}
10199func EstimateProposePerformanceThresholdGas (rp * rocketpool.RocketPool , value * big.Int , blockNumber uint32 , treeNodes []types.VotingTreeNode , opts * bind.TransactOpts ) (gaslimit.Limits , error ) {
102- return protocol .EstimateProposeSetUintGas (rp , fmt .Sprintf ("set %s" , PerformanceThresholdSettingPath ), PerformanceSettingsContractName , PerformanceThresholdSettingPath , value , blockNumber , treeNodes , opts )
100+ return protocol .EstimateProposeSetUintGas (rp , fmt .Sprintf ("set %s" , PerformanceThresholdSettingPath ), NetworkSettingsContractName , PerformanceThresholdSettingPath , value , blockNumber , treeNodes , opts )
103101}
104102
105- // How long a performance exit challenge remains open
103+ // How long a performance exit challenge remains open (stored on-chain in seconds)
106104func GetPerformanceChallengePeriod (rp * rocketpool.RocketPool , opts * bind.CallOpts ) (time.Duration , error ) {
107- performanceSettingsContract , err := getPerformanceSettingsContract (rp , opts )
105+ networkSettingsContract , err := getNetworkSettingsContract (rp , opts )
108106 if err != nil {
109107 return 0 , err
110108 }
111109 value := new (* big.Int )
112- if err := performanceSettingsContract .Call (opts , value , "getPerformanceChallengePeriod" ); err != nil {
110+ if err := networkSettingsContract .Call (opts , value , "getPerformanceChallengePeriod" ); err != nil {
113111 return 0 , fmt .Errorf ("error getting performance challenge period: %w" , err )
114112 }
115- return time .Duration ((* value ).Int64 ()) * time .Hour , nil
113+ return time .Duration ((* value ).Int64 ()) * time .Second , nil
116114}
117115func ProposePerformanceChallengePeriod (rp * rocketpool.RocketPool , value * big.Int , blockNumber uint32 , treeNodes []types.VotingTreeNode , opts * bind.TransactOpts ) (uint64 , common.Hash , error ) {
118- return protocol .ProposeSetUint (rp , fmt .Sprintf ("set %s" , PerformanceChallengePeriodSettingPath ), PerformanceSettingsContractName , PerformanceChallengePeriodSettingPath , value , blockNumber , treeNodes , opts )
116+ return protocol .ProposeSetUint (rp , fmt .Sprintf ("set %s" , PerformanceChallengePeriodSettingPath ), NetworkSettingsContractName , PerformanceChallengePeriodSettingPath , value , blockNumber , treeNodes , opts )
119117}
120118func EstimateProposePerformanceChallengePeriodGas (rp * rocketpool.RocketPool , value * big.Int , blockNumber uint32 , treeNodes []types.VotingTreeNode , opts * bind.TransactOpts ) (gaslimit.Limits , error ) {
121- return protocol .EstimateProposeSetUintGas (rp , fmt .Sprintf ("set %s" , PerformanceChallengePeriodSettingPath ), PerformanceSettingsContractName , PerformanceChallengePeriodSettingPath , value , blockNumber , treeNodes , opts )
119+ return protocol .EstimateProposeSetUintGas (rp , fmt .Sprintf ("set %s" , PerformanceChallengePeriodSettingPath ), NetworkSettingsContractName , PerformanceChallengePeriodSettingPath , value , blockNumber , treeNodes , opts )
122120}
123121
124122// RPL bond required to propose a performance exit
125123func GetPerformanceChallengeBond (rp * rocketpool.RocketPool , opts * bind.CallOpts ) (* big.Int , error ) {
126- performanceSettingsContract , err := getPerformanceSettingsContract (rp , opts )
124+ networkSettingsContract , err := getNetworkSettingsContract (rp , opts )
127125 if err != nil {
128126 return nil , err
129127 }
130128 value := new (* big.Int )
131- if err := performanceSettingsContract .Call (opts , value , "getPerformanceChallengeBond" ); err != nil {
129+ if err := networkSettingsContract .Call (opts , value , "getPerformanceChallengeBond" ); err != nil {
132130 return nil , fmt .Errorf ("error getting performance challenge bond: %w" , err )
133131 }
134132 return * value , nil
135133}
136134func ProposePerformanceChallengeBond (rp * rocketpool.RocketPool , value * big.Int , blockNumber uint32 , treeNodes []types.VotingTreeNode , opts * bind.TransactOpts ) (uint64 , common.Hash , error ) {
137- return protocol .ProposeSetUint (rp , fmt .Sprintf ("set %s" , PerformanceChallengeBondSettingPath ), PerformanceSettingsContractName , PerformanceChallengeBondSettingPath , value , blockNumber , treeNodes , opts )
135+ return protocol .ProposeSetUint (rp , fmt .Sprintf ("set %s" , PerformanceChallengeBondSettingPath ), NetworkSettingsContractName , PerformanceChallengeBondSettingPath , value , blockNumber , treeNodes , opts )
138136}
139137func EstimateProposePerformanceChallengeBondGas (rp * rocketpool.RocketPool , value * big.Int , blockNumber uint32 , treeNodes []types.VotingTreeNode , opts * bind.TransactOpts ) (gaslimit.Limits , error ) {
140- return protocol .EstimateProposeSetUintGas (rp , fmt .Sprintf ("set %s" , PerformanceChallengeBondSettingPath ), PerformanceSettingsContractName , PerformanceChallengeBondSettingPath , value , blockNumber , treeNodes , opts )
141- }
142-
143- // Get contracts
144- var performanceSettingsContractLock sync.Mutex
145-
146- func getPerformanceSettingsContract (rp * rocketpool.RocketPool , opts * bind.CallOpts ) (* rocketpool.Contract , error ) {
147- performanceSettingsContractLock .Lock ()
148- defer performanceSettingsContractLock .Unlock ()
149- return rp .GetContract (PerformanceSettingsContractName , opts )
138+ return protocol .EstimateProposeSetUintGas (rp , fmt .Sprintf ("set %s" , PerformanceChallengeBondSettingPath ), NetworkSettingsContractName , PerformanceChallengeBondSettingPath , value , blockNumber , treeNodes , opts )
150139}
0 commit comments