Skip to content

Commit

Permalink
vochain: allow set census size if dynamicCensus=false
Browse files Browse the repository at this point in the history
Signed-off-by: p4u <[email protected]>
  • Loading branch information
p4u committed Jun 17, 2024
1 parent 8db2a08 commit 00072b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
10 changes: 7 additions & 3 deletions vochain/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ func TestSetProcessCensusSize(t *testing.T) {
process := &models.Process{
StartBlock: 1,
EnvelopeType: &models.EnvelopeType{EncryptedVotes: false},
Mode: &models.ProcessMode{Interruptible: true, DynamicCensus: true},
Mode: &models.ProcessMode{Interruptible: true, DynamicCensus: false},
VoteOptions: &models.ProcessVoteOptions{MaxCount: 16, MaxValue: 16},
Status: models.ProcessStatus_READY,
EntityId: accounts[0].Address().Bytes(),
Expand All @@ -528,8 +528,12 @@ func TestSetProcessCensusSize(t *testing.T) {
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, proc.MaxCensusSize, qt.Equals, uint64(2))

// Set census size and new root (should work)
qt.Assert(t, testSetProcessCensus(t, pid, accounts[0], app, util.RandomBytes(32), &censusURI, 5), qt.IsNil)
// Set census size with root (should failg since dynamicCensus=false)
qt.Assert(t, testSetProcessCensus(t, pid, accounts[0], app, util.RandomBytes(32), nil, 5), qt.IsNotNil)
app.AdvanceTestBlock()

// Set census size (should work)
qt.Assert(t, testSetProcessCensus(t, pid, accounts[0], app, nil, nil, 5), qt.IsNil)
app.AdvanceTestBlock()

proc, err = app.State.Process(pid, true)
Expand Down
23 changes: 11 additions & 12 deletions vochain/state/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,17 @@ func (v *State) SetProcessCensus(pid, censusRoot []byte, censusURI string, censu
if err != nil {
return err
}
// check valid state transition
// dynamic census
if !process.Mode.DynamicCensus {
return fmt.Errorf(
"cannot update census, only processes with dynamic census can update their census")
}
// census origin
if !CensusOrigins[process.CensusOrigin].AllowCensusUpdate {
return fmt.Errorf(
"cannot update census, invalid census origin: %s", process.CensusOrigin)
// check dynamic census only if root is being updated
if censusRoot != nil {
if !process.Mode.DynamicCensus {
return fmt.Errorf(
"cannot update census, only processes with dynamic census can update their root")
}
// census origin
if !CensusOrigins[process.CensusOrigin].AllowCensusUpdate {
return fmt.Errorf(
"cannot update census, census origin %s does not allow update", process.CensusOrigin)
}
}
// status
if !(process.Status == models.ProcessStatus_READY) &&
Expand All @@ -352,8 +353,6 @@ func (v *State) SetProcessCensus(pid, censusRoot []byte, censusURI string, censu
if commit {
if censusRoot != nil {
process.CensusRoot = censusRoot
}
if censusURI != "" {
process.CensusURI = &censusURI
}
if censusSize > 0 {
Expand Down

0 comments on commit 00072b3

Please sign in to comment.