forked from dymensionxyz/dymint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: block production misbehavior detection (dymensionxyz#1071)
Co-authored-by: Faulty Tolly <@faulttolerance.net>
- Loading branch information
1 parent
57bc89e
commit 9aef1d0
Showing
28 changed files
with
2,005 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package block | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/dymensionxyz/dymint/node/events" | ||
uevent "github.com/dymensionxyz/dymint/utils/event" | ||
) | ||
|
||
// FraudHandler is an interface that defines a method to handle faults. | ||
// Contract: should not be blocking. | ||
type FraudHandler interface { | ||
// HandleFault handles a fault that occurred in the system. | ||
// The fault is passed as an error type. | ||
HandleFault(ctx context.Context, fault error) | ||
} | ||
|
||
// FreezeHandler is used to handle faults coming from executing and validating blocks. | ||
// once a fault is detected, it publishes a DataHealthStatus event to the pubsub which sets the node in a frozen state. | ||
type FreezeHandler struct { | ||
m *Manager | ||
} | ||
|
||
func (f FreezeHandler) HandleFault(ctx context.Context, fault error) { | ||
uevent.MustPublish(ctx, f.m.Pubsub, &events.DataHealthStatus{Error: fault}, events.HealthStatusList) | ||
} | ||
|
||
func NewFreezeHandler(manager *Manager) *FreezeHandler { | ||
return &FreezeHandler{ | ||
m: manager, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package block_test | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/dymensionxyz/gerr-cosmos/gerrc" | ||
) | ||
|
||
type mockError struct { | ||
name string | ||
data string | ||
} | ||
|
||
func (m mockError) Error() string { | ||
return "some string" | ||
} | ||
|
||
func (mockError) Unwrap() error { | ||
return gerrc.ErrFault | ||
} | ||
|
||
func TestErrorIsErrFault(t *testing.T) { | ||
err := mockError{name: "test", data: "test"} | ||
|
||
if !errors.Is(err, gerrc.ErrFault) { | ||
t.Error("Expected Is to return true") | ||
} | ||
|
||
anotherErr := errors.New("some error") | ||
|
||
if errors.Is(anotherErr, gerrc.ErrFault) { | ||
t.Error("Expected Is to return false") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.