Skip to content

Commit

Permalink
indexer: update maxCensusSize when SET_PROCESS_CENSUS
Browse files Browse the repository at this point in the history
Signed-off-by: p4u <[email protected]>
  • Loading branch information
p4u committed Jun 11, 2024
1 parent dc27947 commit c12e60a
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 23 deletions.
21 changes: 12 additions & 9 deletions vochain/indexer/db/processes.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vochain/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ func (idx *Indexer) OnTransferTokens(tx *vochaintx.TokenTransfer) {

// OnCensusUpdate adds the process to blockUpdateProcs in order to update the census.
// This function call is triggered by the SET_PROCESS_CENSUS tx.
func (idx *Indexer) OnCensusUpdate(pid, _ []byte, _ string) {
func (idx *Indexer) OnCensusUpdate(pid, _ []byte, _ string, _ uint64) {
idx.blockMu.Lock()
defer idx.blockMu.Unlock()
idx.blockUpdateProcs[string(pid)] = true
Expand Down
15 changes: 8 additions & 7 deletions vochain/indexer/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,14 @@ func (idx *Indexer) updateProcess(ctx context.Context, queries *indexerdb.Querie

// Update the process in the indexer database
if _, err := queries.UpdateProcessFromState(ctx, indexerdb.UpdateProcessFromStateParams{
ID: pid,
CensusRoot: nonNullBytes(p.CensusRoot),
CensusUri: p.GetCensusURI(),
PrivateKeys: indexertypes.EncodeJSON(p.EncryptionPrivateKeys),
PublicKeys: indexertypes.EncodeJSON(p.EncryptionPublicKeys),
Metadata: p.GetMetadata(),
Status: int64(p.Status),
ID: pid,
CensusRoot: nonNullBytes(p.CensusRoot),
CensusUri: p.GetCensusURI(),
PrivateKeys: indexertypes.EncodeJSON(p.EncryptionPrivateKeys),
PublicKeys: indexertypes.EncodeJSON(p.EncryptionPublicKeys),
Metadata: p.GetMetadata(),
Status: int64(p.Status),
MaxCensusSize: int64(p.GetMaxCensusSize()),
}); err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion vochain/indexer/queries/processes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ SET census_root = sqlc.arg(census_root),
private_keys = sqlc.arg(private_keys),
public_keys = sqlc.arg(public_keys),
metadata = sqlc.arg(metadata),
status = sqlc.arg(status)
status = sqlc.arg(status),
max_census_size = sqlc.arg(max_census_size)
WHERE id = sqlc.arg(id);

-- name: GetProcessStatus :one
Expand Down
2 changes: 1 addition & 1 deletion vochain/keykeeper/keykeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (*KeyKeeper) OnNewTx(_ *vochaintx.Tx, _ uint32, _ int32) {}
func (*KeyKeeper) OnBeginBlock(_ state.BeginBlock) {}

// OnCensusUpdate is not used by the KeyKeeper
func (*KeyKeeper) OnCensusUpdate(_, _ []byte, _ string) {}
func (*KeyKeeper) OnCensusUpdate(_, _ []byte, _ string, _ uint64) {}

// OnCancel does nothing
func (k *KeyKeeper) OnCancel(_ []byte, _ int32) {}
2 changes: 1 addition & 1 deletion vochain/offchaindatahandler/offchaindatahandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (d *OffChainDataHandler) OnProcess(p *models.Process, _ int32) {
}

// OnCensusUpdate is triggered when the census is updated during an election.
func (d *OffChainDataHandler) OnCensusUpdate(pid, censusRoot []byte, censusURI string) {
func (d *OffChainDataHandler) OnCensusUpdate(pid, censusRoot []byte, censusURI string, _ uint64) {
if d.importOnlyNew && !d.isSynced {
return
}
Expand Down
2 changes: 1 addition & 1 deletion vochain/state/eventlistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type EventListener interface {
OnSetAccount(addr []byte, account *Account)
OnTransferTokens(tx *vochaintx.TokenTransfer)
OnSpendTokens(addr []byte, txType models.TxType, cost uint64, reference string)
OnCensusUpdate(pid, censusRoot []byte, censusURI string)
OnCensusUpdate(pid, censusRoot []byte, censusURI string, censusSize uint64)
Commit(height uint32) (err error)
OnBeginBlock(BeginBlock)
Rollback()
Expand Down
2 changes: 1 addition & 1 deletion vochain/state/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func (v *State) SetProcessCensus(pid, censusRoot []byte, censusURI string, censu
return err
}
for _, l := range v.eventListeners {
l.OnCensusUpdate(process.ProcessId, process.CensusRoot, censusURI)
l.OnCensusUpdate(process.ProcessId, process.CensusRoot, censusURI, censusSize)
}
}

Expand Down
2 changes: 1 addition & 1 deletion vochain/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (*Listener) OnCancel(_ []byte, _ int32)
func (*Listener) OnProcessKeys(_ []byte, _ string, _ int32) {}
func (*Listener) OnRevealKeys(_ []byte, _ string, _ int32) {}
func (*Listener) OnProcessResults(_ []byte, _ *models.ProcessResult, _ int32) {}
func (*Listener) OnCensusUpdate(_, _ []byte, _ string) {}
func (*Listener) OnCensusUpdate(_, _ []byte, _ string, _ uint64) {}
func (*Listener) OnSetAccount(_ []byte, _ *Account) {}
func (*Listener) OnTransferTokens(_ *vochaintx.TokenTransfer) {}
func (*Listener) OnSpendTokens(_ []byte, _ models.TxType, _ uint64, _ string) {}
Expand Down

0 comments on commit c12e60a

Please sign in to comment.