Skip to content

Commit

Permalink
Allow min commitment of single state sync event
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed May 6, 2023
1 parent 062414f commit 25cd759
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
17 changes: 7 additions & 10 deletions consensus/polybft/state_sync_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,17 +502,14 @@ func (s *stateSyncManager) buildCommitment() error {
s.lock.Lock()
defer s.lock.Unlock()

epoch := s.epoch
fromIndex := s.nextCommittedIndex

stateSyncEvents, err := s.state.StateSyncStore.getStateSyncEventsForCommitment(fromIndex,
fromIndex+s.config.maxCommitmentSize-1)
stateSyncEvents, err := s.state.StateSyncStore.getStateSyncEventsForCommitment(s.nextCommittedIndex,
s.nextCommittedIndex+s.config.maxCommitmentSize-1)
if err != nil && !errors.Is(err, errNotEnoughStateSyncs) {
return fmt.Errorf("failed to get state sync events for commitment. Error: %w", err)
}

if len(stateSyncEvents) < minCommitmentSize {
// there is not enough state sync events to build at least the minimum commitment
if len(stateSyncEvents) == 0 {
// there are no state sync events
return nil
}

Expand All @@ -522,7 +519,7 @@ func (s *stateSyncManager) buildCommitment() error {
return nil
}

commitment, err := NewPendingCommitment(epoch, stateSyncEvents)
commitment, err := NewPendingCommitment(s.epoch, stateSyncEvents)
if err != nil {
return err
}
Expand All @@ -544,7 +541,7 @@ func (s *stateSyncManager) buildCommitment() error {
Signature: signature,
}

if _, err = s.state.StateSyncStore.insertMessageVote(epoch, hashBytes, sig); err != nil {
if _, err = s.state.StateSyncStore.insertMessageVote(s.epoch, hashBytes, sig); err != nil {
return fmt.Errorf(
"failed to insert signature for hash=%v to the state. Error: %w",
hex.EncodeToString(hashBytes),
Expand All @@ -557,7 +554,7 @@ func (s *stateSyncManager) buildCommitment() error {
Hash: hashBytes,
Signature: signature,
From: s.config.key.String(),
EpochNumber: epoch,
EpochNumber: s.epoch,
})

s.logger.Debug(
Expand Down
11 changes: 8 additions & 3 deletions consensus/polybft/state_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,21 @@ func getCommitmentMessageSignedTx(txs []*types.Transaction) (*CommitmentMessageS
}

func createMerkleTree(stateSyncEvents []*contractsapi.StateSyncedEvent) (*merkle.MerkleTree, error) {
ssh := make([][]byte, len(stateSyncEvents))
stateSyncData := make([][]byte, len(stateSyncEvents))

for i, sse := range stateSyncEvents {
data, err := sse.EncodeAbi()
if err != nil {
return nil, err
}

ssh[i] = data
stateSyncData[i] = data
}

return merkle.NewMerkleTree(ssh)
if len(stateSyncEvents) == 1 {
//nolint:makezero
stateSyncData = append(stateSyncData, nil)
}

return merkle.NewMerkleTree(stateSyncData)
}
2 changes: 1 addition & 1 deletion e2e-polybft/e2e/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func TestE2E_Bridge_Transfers(t *testing.T) {

t.Run("multiple deposit batches per epoch", func(t *testing.T) {
const (
depositsSubset = 2
depositsSubset = 1
)

initialBlockNum, err := childEthEndpoint.BlockNumber()
Expand Down

0 comments on commit 25cd759

Please sign in to comment.