Skip to content

Commit

Permalink
Process all alerts on sync
Browse files Browse the repository at this point in the history
  • Loading branch information
galt-tr committed Jan 25, 2024
1 parent de4ccc2 commit ff47577
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/config/envs/local.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
"p2p": {
"ip": "0.0.0.0",
"port": "9906",
"alert_system_protocol_id": "/bitcoin-stn/alert-system/0.0.1",
"alert_system_protocol_id": "/bitcoin/alert-system/0.0.1",
"bootstrap_peer": "",
"private_key_path": "",
"topic_name": "alert_system_stn"
"topic_name": "alert_system"
},
"rpc_connections": [
{
Expand Down
18 changes: 10 additions & 8 deletions app/p2p/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ func (s *StreamThread) Sync(ctx context.Context) error {
s.config.Services.Log.Debugf("requested latest sequence in stream %s", s.stream.ID())

return s.ProcessSyncMessage(ctx)

}

// ProcessSyncMessage will process the sync message
func (s *StreamThread) ProcessSyncMessage(ctx context.Context) error {

for {
b, err := wire.ReadVarBytes(s.stream, 0, math.MaxUint64, config.ApplicationName)
if err != nil {
Expand Down Expand Up @@ -184,14 +186,14 @@ func (s *StreamThread) ProcessGotSequenceNumber(msg *SyncMessage) error {
a.SerializeData()

// Process the alert (if it's a set keys alert)
if a.GetAlertType() == models.AlertTypeSetKeys || a.GetAlertType() == models.AlertTypeInvalidateBlock {
ak := a.ProcessAlertMessage()
if err = ak.Read(a.GetRawMessage()); err != nil {
return err
}
if err = ak.Do(s.ctx); err != nil {
return err
}
// TODO: For now lets just process all alerts... why not?
// if a.GetAlertType() == models.AlertTypeSetKeys || a.GetAlertType() == models.AlertTypeInvalidateBlock {
ak := a.ProcessAlertMessage()
if err = ak.Read(a.GetRawMessage()); err != nil {
return err
}
if err = ak.Do(s.ctx); err != nil {
s.config.Services.Log.Errorf("failed to process alert %d; err: %v", a.SequenceNumber, err.Error())
}

// Save the alert
Expand Down

0 comments on commit ff47577

Please sign in to comment.