Skip to content

Commit

Permalink
Merge branch 'rc/v1.6.0' into fix-snapshots-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau authored Dec 12, 2023
2 parents 81f69cf + 0cf6128 commit d27b443
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/node/config/systemSmartContractsConfig.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
[GovernanceSystemSCConfig.Active]
ProposalCost = "1000000000000000000000" #1000 eGLD
LostProposalFee = "10000000000000000000" #10 eGLD
MinQuorum = 0.5 #fraction of value 0.5 - 50%
MinQuorum = 0.2 #fraction of value 0.2 - 20%
MinPassThreshold = 0.5 #fraction of value 0.5 - 50%
MinVetoThreshold = 0.33 #fraction of value 0.33 - 33%

Expand Down
4 changes: 3 additions & 1 deletion process/block/metablock.go
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,7 @@ func (mp *metaProcessor) createAndProcessCrossMiniBlocksDstMe(
false)

if createErr != nil {
mp.hdrsForCurrBlock.mutHdrsForBlock.Unlock()
return nil, 0, 0, createErr
}

Expand Down Expand Up @@ -1999,6 +2000,8 @@ func (mp *metaProcessor) createShardInfo() ([]data.ShardDataHandler, error) {
}

mp.hdrsForCurrBlock.mutHdrsForBlock.Lock()
defer mp.hdrsForCurrBlock.mutHdrsForBlock.Unlock()

for hdrHash, headerInfo := range mp.hdrsForCurrBlock.hdrHashAndInfo {
if !headerInfo.usedInBlock {
continue
Expand Down Expand Up @@ -2048,7 +2051,6 @@ func (mp *metaProcessor) createShardInfo() ([]data.ShardDataHandler, error) {

shardInfo = append(shardInfo, &shardData)
}
mp.hdrsForCurrBlock.mutHdrsForBlock.Unlock()

log.Debug("created shard data",
"size", len(shardInfo),
Expand Down
1 change: 1 addition & 0 deletions process/block/shardblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,7 @@ func (sp *shardProcessor) createAndProcessMiniBlocksDstMe(haveTime func() bool)

shouldContinue, errCreated := sp.createMbsAndProcessCrossShardTransactionsDstMe(createAndProcessInfo)
if errCreated != nil {
sp.hdrsForCurrBlock.mutHdrsForBlock.Unlock()
return nil, errCreated
}
if !shouldContinue {
Expand Down
26 changes: 21 additions & 5 deletions vm/systemSmartContracts/governance.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func (g *governanceContract) proposal(args *vmcommon.ContractCallInput) vmcommon
logEntry := &vmcommon.LogEntry{
Identifier: []byte(args.Function),
Address: args.CallerAddr,
Topics: [][]byte{nonceAsBytes, commitHash, args.Arguments[1], args.Arguments[1], args.Arguments[2]},
Topics: [][]byte{nonceAsBytes, commitHash, args.Arguments[1], args.Arguments[2]},
}
g.eei.AddLogEntry(logEntry)

Expand Down Expand Up @@ -763,11 +763,28 @@ func (g *governanceContract) viewUserVoteHistory(args *vmcommon.ContractCallInpu
return vmcommon.UserError
}

g.eei.Finish([]byte(userVotes.String()))
g.finishWithIntValue(len(userVotes.Delegated)) // first we send the number of delegated nonces and afterward the nonces
for _, val := range userVotes.Delegated {
g.finishWithIntValue(int(val))
}

g.finishWithIntValue(len(userVotes.Direct)) // then we send the number of direct nonces and afterward the nonces
for _, val := range userVotes.Direct {
g.finishWithIntValue(int(val))
}

return vmcommon.Ok
}

func (g *governanceContract) finishWithIntValue(value int) {
if value == 0 {
g.eei.Finish([]byte{0})
return
}

g.eei.Finish(big.NewInt(int64(value)).Bytes())
}

func (g *governanceContract) viewProposal(args *vmcommon.ContractCallInput) vmcommon.ReturnCode {
err := g.checkViewFuncArguments(args, 1)
if err != nil {
Expand Down Expand Up @@ -855,8 +872,7 @@ func (g *governanceContract) addNewVote(vote string, power *big.Int, proposal *G
}

// computeVotingPower returns the voting power for a value. The value can be either a balance or
//
// the staked value for a validator
// the staked value for a validator
func (g *governanceContract) computeVotingPower(value *big.Int) (*big.Int, error) {
minValue, err := g.getMinValueToVote()
if err != nil {
Expand All @@ -867,7 +883,7 @@ func (g *governanceContract) computeVotingPower(value *big.Int) (*big.Int, error
return nil, vm.ErrNotEnoughStakeToVote
}

return big.NewInt(0).Sqrt(value), nil
return big.NewInt(0).Set(value), nil // linear computation
}

// function iterates over all delegation contracts and verifies balances of the given account and makes a sum of it
Expand Down
28 changes: 26 additions & 2 deletions vm/systemSmartContracts/governance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,10 @@ func TestGovernanceContract_ProposalOK(t *testing.T) {
retCode := gsc.Execute(callInput)

require.Equal(t, vmcommon.Ok, retCode)
logsEntry := gsc.eei.GetLogs()
assert.Equal(t, 1, len(logsEntry))
expectedTopics := [][]byte{{1}, proposalIdentifier, []byte("50"), []byte("55")}
assert.Equal(t, expectedTopics, logsEntry[0].Topics)
}

func TestGovernanceContract_VoteWithBadArgsOrCallValue(t *testing.T) {
Expand Down Expand Up @@ -1299,7 +1303,7 @@ func TestGovernanceContract_GetVotingPower(t *testing.T) {
require.Equal(t, vmcommon.Ok, retCode)

vmOutput := eei.CreateVMOutput()
require.Equal(t, big.NewInt(10).Bytes(), vmOutput.ReturnData[0])
require.Equal(t, big.NewInt(120).Bytes(), vmOutput.ReturnData[0])
}

func TestGovernanceContract_GetVVotingPowerWrongCallValue(t *testing.T) {
Expand Down Expand Up @@ -1440,13 +1444,17 @@ func TestGovernanceContract_ViewUserHistory(t *testing.T) {
callerAddress := []byte("address")
args := createMockGovernanceArgs()
returnMessage := ""
finishedMessages := make([][]byte, 0)
mockEEI := &mock.SystemEIStub{
GetStorageFromAddressCalled: func(_ []byte, _ []byte) []byte {
return []byte("invalid data")
},
AddReturnMessageCalled: func(msg string) {
returnMessage = msg
},
FinishCalled: func(value []byte) {
finishedMessages = append(finishedMessages, value)
},
}
args.Eei = mockEEI

Expand All @@ -1463,17 +1471,33 @@ func TestGovernanceContract_ViewUserHistory(t *testing.T) {
callInput.Arguments = [][]byte{callerAddress}
retCode = gsc.Execute(callInput)
require.Equal(t, vmcommon.Ok, retCode)
expectedMessaged := [][]byte{
{0}, // 0 delegated values
{0}, // 0 direct values
}
assert.Equal(t, expectedMessaged, finishedMessages)

mockEEI.GetStorageCalled = func(key []byte) []byte {
proposalBytes, _ := args.Marshalizer.Marshal(&OngoingVotedList{
Delegated: []uint64{1, 2},
Direct: []uint64{1, 2},
Direct: []uint64{3, 4, 5},
})
return proposalBytes
}

finishedMessages = make([][]byte, 0)
retCode = gsc.Execute(callInput)
require.Equal(t, vmcommon.Ok, retCode)
expectedMessaged = [][]byte{
{2}, // 2 delegated values
{1},
{2},
{3}, // 3 direct values
{3},
{4},
{5},
}
assert.Equal(t, expectedMessaged, finishedMessages)
}

func TestGovernanceContract_ViewProposal(t *testing.T) {
Expand Down

0 comments on commit d27b443

Please sign in to comment.