@@ -335,119 +335,3 @@ func initializeBase(govBaseAddress common.Address, param map[string]string) ([]p
335335 return sp , nil
336336}
337337
338- // upgradeBase performs a migration-style upgrade for GovBase storage.
339- // Only parameters present in param are written to StateParam.
340- // Missing keys are not appended, so state.SetState is never called for them,
341- // preserving existing on-chain values automatically.
342- func upgradeBase (govBaseAddress common.Address , param map [string ]string ) ([]params.StateParam , error ) {
343- sp := make ([]params.StateParam , 0 )
344-
345- if quorumStr , ok := param [GOV_BASE_PARAM_QUORUM ]; ok {
346- quorum , err := strconv .ParseUint (quorumStr , 10 , 64 )
347- if err != nil {
348- return nil , fmt .Errorf ("`systemContracts.govBase.params.quorum`: %w" , err )
349- }
350- if quorum == 0 {
351- return nil , fmt .Errorf ("`systemContracts.govBase.params.quorum` must be greater than 0" )
352- }
353- sp = append (sp , params.StateParam {
354- Address : govBaseAddress ,
355- Key : common .HexToHash (SLOT_GOV_BASE_quorum ),
356- Value : common .BigToHash (big .NewInt (int64 (quorum ))),
357- })
358- }
359-
360- if expiryStr , ok := param [GOV_BASE_PARAM_EXPIRY ]; ok {
361- expiry , err := strconv .ParseUint (expiryStr , 10 , 64 )
362- if err != nil {
363- return nil , fmt .Errorf ("`systemContracts.govBase.params.expiry`: %w" , err )
364- }
365- sp = append (sp , params.StateParam {
366- Address : govBaseAddress ,
367- Key : common .HexToHash (SLOT_GOV_BASE_proposalExpiry ),
368- Value : common .BigToHash (big .NewInt (int64 (expiry ))),
369- })
370- }
371-
372- if maxProposalsStr , ok := param [GOV_BASE_PARAM_MAX_PROPOSALS ]; ok {
373- maxProposals , err := strconv .ParseUint (maxProposalsStr , 10 , 64 )
374- if err != nil {
375- return nil , fmt .Errorf ("`systemContracts.govBase.params.maxProposals`: %w" , err )
376- }
377- if maxProposals < 1 || maxProposals > 50 {
378- return nil , fmt .Errorf ("`systemContracts.govBase.params.maxProposals` must be between 1 and 50, got %d" , maxProposals )
379- }
380- sp = append (sp , params.StateParam {
381- Address : govBaseAddress ,
382- Key : common .HexToHash (SLOT_GOV_BASE_maxActiveProposalsPerMember ),
383- Value : common .BigToHash (big .NewInt (int64 (maxProposals ))),
384- })
385- }
386-
387- // members: only process if explicitly provided. Mapping structures are preserved
388- // automatically when not appended.
389- if membersStr , ok := param [GOV_BASE_PARAM_MEMBERS ]; ok {
390- memberAddresses := splitAndTrim (membersStr , "," )
391- uniqueMembers := make ([]common.Address , 0 )
392- seen := make (map [common.Address ]struct {})
393- for _ , addrStr := range memberAddresses {
394- member := common .HexToAddress (addrStr )
395- if member == (common.Address {}) {
396- return nil , fmt .Errorf ("`systemContracts.govBase.params.members` contains invalid zero address" )
397- }
398- if _ , exists := seen [member ]; ! exists {
399- seen [member ] = struct {}{}
400- uniqueMembers = append (uniqueMembers , member )
401- }
402- }
403-
404- const MAX_MEMBERS = 255
405- if len (uniqueMembers ) > MAX_MEMBERS {
406- return nil , fmt .Errorf ("`systemContracts.govBase.params.members` count (%d) exceeds maximum allowed (%d)" , len (uniqueMembers ), MAX_MEMBERS )
407- }
408-
409- versionStr , ok2 := param [GOV_BASE_PARAM_MEMBER_VERSION ]
410- if ! ok2 {
411- return nil , fmt .Errorf ("`systemContracts.govBase.params.memberVersion` is required when `systemContracts.govBase.params.members` is set" )
412- }
413- versionInt , err := strconv .ParseUint (versionStr , 10 , 64 )
414- if err != nil {
415- return nil , fmt .Errorf ("`systemContracts.govBase.params.memberVersion`: %w" , err )
416- }
417- version := new (big.Int ).SetUint64 (versionInt )
418-
419- membersSlot := common .HexToHash (SLOT_GOV_BASE_members )
420- versionedMemberListSlot := common .HexToHash (SLOT_GOV_BASE_versionedMemberList )
421- versionSlot := common .HexToHash (SLOT_GOV_BASE_version )
422- memberIndexByVersionSlot := common .HexToHash (SLOT_GOV_BASE_memberIndexByVersion )
423- quorumByVersionSlot := common .HexToHash (SLOT_GOV_BASE_quorumByVersion )
424-
425- memberData := Member {IsActive : true , JoinedAt : 0 }.ToHash ()
426- currentIdx := uint64 (0 )
427- for _ , member := range uniqueMembers {
428- if currentIdx >= MAX_MEMBERS {
429- return nil , fmt .Errorf ("member index overflow: currentIdx (%d) >= MAX_MEMBERS (%d)" , currentIdx , MAX_MEMBERS )
430- }
431- sp = append (sp ,
432- params.StateParam {Address : govBaseAddress , Key : CalculateMappingSlot (membersSlot , member ), Value : memberData },
433- params.StateParam {Address : govBaseAddress , Key : CalculateDynamicSlot (CalculateMappingSlot (versionedMemberListSlot , version ), new (big.Int ).SetUint64 (currentIdx )), Value : common .BytesToHash (member .Bytes ())},
434- params.StateParam {Address : govBaseAddress , Key : CalculateMappingSlot (CalculateMappingSlot (memberIndexByVersionSlot , version ), member ), Value : common .BigToHash (new (big.Int ).SetUint64 (currentIdx + 1 ))},
435- )
436- currentIdx ++
437- }
438- if currentIdx > 0 {
439- sp = append (sp , params.StateParam {Address : govBaseAddress , Key : CalculateMappingSlot (versionedMemberListSlot , version ), Value : common .BigToHash (new (big.Int ).SetUint64 (currentIdx ))})
440- }
441- sp = append (sp , params.StateParam {Address : govBaseAddress , Key : versionSlot , Value : common .BigToHash (version )})
442-
443- // quorumByVersion: only if quorum was also provided
444- if quorumStr , ok := param [GOV_BASE_PARAM_QUORUM ]; ok {
445- quorum , _ := strconv .ParseUint (quorumStr , 10 , 64 )
446- if quorum > 0 {
447- sp = append (sp , params.StateParam {Address : govBaseAddress , Key : CalculateMappingSlot (quorumByVersionSlot , version ), Value : common .BigToHash (new (big.Int ).SetUint64 (quorum ))})
448- }
449- }
450- }
451-
452- return sp , nil
453- }
0 commit comments