-
Notifications
You must be signed in to change notification settings - Fork 58
vrfs attack Byzantine test #673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c72c5cb
vrfs spam test
rrrooommmaaa 5a242bc
more lenient tests
rrrooommmaaa 138cf4f
Add mutex while spamming VRFs and force generation of new VRF for nex…
fabioDMFerreira b82d0bc
Add spam VRFS test
fabioDMFerreira 46fd3ce
fix lint issues
fabioDMFerreira 86a20e5
Enforce spammer to be a replica
fabioDMFerreira c305628
lock notarization in a honest miner until receiving the spamming VRF
fabioDMFerreira afa284c
small adaptations to test description
fabioDMFerreira 1476014
fix test configuration
fabioDMFerreira be0c543
move GetNodeTypeAndTypeRank to different file
fabioDMFerreira 1ab5dd9
move back GetNodeTypeAndTypeRank
fabioDMFerreira 584e116
rename property related with the test case configuration (RoundHasFin…
fabioDMFerreira ffdcb20
remove duplicated conductor utils and refactor round has finalized te…
fabioDMFerreira 2177208
remove unnecessary integration tests configuration hook
fabioDMFerreira f71dbee
fix spam next round vrf
fabioDMFerreira 087a24d
fix lock notarization directive in registry
fabioDMFerreira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
$wsl_ip=wsl hostname -I | ||
$port=15210 # conductor server port | ||
netsh int ipv4 reset | ||
netsh interface portproxy add v4tov4 listenport=$port listenaddress=0.0.0.0 connectport=$port connectaddress=$wsl_ip | ||
echo "bridging $wsl_ip" |
This file contains hidden or 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 hidden or 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
49 changes: 49 additions & 0 deletions
49
code/go/0chain.net/chaincore/chain/utils_integration_tests.go
This file contains hidden or 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,49 @@ | ||
//go:build integration_tests | ||
// +build integration_tests | ||
|
||
package chain | ||
|
||
import ( | ||
"0chain.net/chaincore/node" | ||
crpc "0chain.net/conductor/conductrpc" | ||
"0chain.net/conductor/config/cases" | ||
) | ||
|
||
// SplitGoodAndBadNodes nodes list by given IsGoodOrBad. | ||
func SplitGoodAndBadNodes(s *crpc.State, igb crpc.IsGoodOrBad, nodes []*node.Node) ( | ||
good, bad []*node.Node) { | ||
|
||
for _, n := range nodes { | ||
if igb.IsBad(s, n.GetKey()) { | ||
bad = append(bad, n) | ||
} else if igb.IsGood(s, n.GetKey()) { | ||
good = append(good, n) | ||
} | ||
} | ||
return | ||
} | ||
|
||
// IsSpammer checks whether a node is a spammer. | ||
// A list of spammers names with format "miner-x" are passed, then the x is extracted and compared with the node index. | ||
func IsSpammer(spammers []cases.NodeTypeTypeRank, roundNum int64) (isSpammer bool) { | ||
isSpammer = false | ||
|
||
nodeType, typeRank := GetNodeTypeAndTypeRank(roundNum) | ||
|
||
for _, spammer := range spammers { | ||
if spammer.NodeType == nodeType && spammer.TypeRank == typeRank { | ||
return true | ||
} | ||
} | ||
|
||
return | ||
} | ||
|
||
// IsSpamReceiver checks whether a node is the spam receiver set in the round_has_finalized configuration. | ||
func IsSpamReceiver(state *crpc.State, roundNum int64) (isSpamReceiver bool) { | ||
isSpamReceiver = false | ||
|
||
nodeType, typeRank := GetNodeTypeAndTypeRank(roundNum) | ||
|
||
return state.RoundHasFinalizedConfig.SpammingReceiver.NodeType == nodeType && state.RoundHasFinalizedConfig.SpammingReceiver.TypeRank == typeRank | ||
} |
This file contains hidden or 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,84 @@ | ||
package cases | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
type ( | ||
// RoundHasFinalized represents implementation of the TestCase interface. | ||
RoundHasFinalized struct { | ||
res *RoundInfo | ||
|
||
roundID int | ||
|
||
prepared chan struct{} | ||
} | ||
) | ||
|
||
var ( | ||
// Ensure RoundHasFinalized implements TestCase interface. | ||
_ TestCase = (*RoundHasFinalized)(nil) | ||
) | ||
|
||
// NewRoundHasFinalized creates initialised RoundHasFinalized. | ||
func NewRoundHasFinalized() *RoundHasFinalized { | ||
return &RoundHasFinalized{ | ||
prepared: make(chan struct{}), | ||
} | ||
} | ||
|
||
// Check implements TestCase interface. | ||
func (n *RoundHasFinalized) Check(ctx context.Context) (success bool, err error) { | ||
select { | ||
case <-ctx.Done(): | ||
return false, errors.New("cases state is not prepared, context is done") | ||
|
||
case <-n.prepared: | ||
return n.check() | ||
} | ||
} | ||
|
||
func (n *RoundHasFinalized) check() (success bool, err error) { | ||
if !n.res.IsFinalised { | ||
return false, errors.New("expected the round to be finalised") | ||
} | ||
|
||
return true, nil | ||
} | ||
|
||
// Configure implements TestCase interface. | ||
func (n *RoundHasFinalized) Configure(blob []byte) error { | ||
roundIDStr := string(blob) | ||
|
||
roundID, err := strconv.Atoi(roundIDStr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
n.roundID = roundID | ||
|
||
return nil | ||
} | ||
|
||
// AddResult implements TestCase interface. | ||
func (n *RoundHasFinalized) AddResult(blob []byte) error { | ||
roundInfo := &RoundInfo{} | ||
|
||
if err := roundInfo.Decode(blob); err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("adding result -> %+v %+v\n", roundInfo, n.roundID) | ||
|
||
if roundInfo.Num == int64(n.roundID) && (n.res == nil || n.res.Num == 0) { | ||
defer func() { | ||
n.prepared <- struct{}{} | ||
}() | ||
n.res = roundInfo | ||
} | ||
|
||
return nil | ||
} |
This file contains hidden or 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 hidden or 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
50 changes: 50 additions & 0 deletions
50
code/go/0chain.net/conductor/config/cases/round_has_finalized.go
This file contains hidden or 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,50 @@ | ||
package cases | ||
|
||
import ( | ||
"0chain.net/conductor/cases" | ||
"github.com/mitchellh/mapstructure" | ||
) | ||
|
||
type ( | ||
// NodeTypeTypeRank holds the information about the node type and the type rank of the miner | ||
// If node type is 0 the miner is a generator/leader. Otherwise, it is a replica. | ||
NodeTypeTypeRank struct { | ||
NodeType int `json:"node_type" yaml:"node_type" mapstructure:"node_type"` | ||
TypeRank int `json:"type_rank" yaml:"type_rank" mapstructure:"type_rank"` | ||
} | ||
// RoundHasFinalized represents TestCaseConfigurator implementation. | ||
RoundHasFinalized struct { | ||
Spammers []NodeTypeTypeRank `json:"spammers" yaml:"spammers" mapstructure:"spammers"` | ||
SpammingReceiver NodeTypeTypeRank `json:"spamming_receiver" yaml:"spamming_receiver" mapstructure:"spamming_receiver"` | ||
Round int `json:"round" yaml:"round" mapstructure:"round"` | ||
} | ||
) | ||
|
||
const ( | ||
RoundHasFinalizedName = "round has finalized" | ||
) | ||
|
||
var ( | ||
// Ensure RoundHasFinalized implements TestCaseConfigurator. | ||
_ TestCaseConfigurator = (*RoundHasFinalized)(nil) | ||
) | ||
|
||
// NewRoundHasFinalized creates initialised RoundHasFinalized. | ||
func NewRoundHasFinalized() *RoundHasFinalized { | ||
return &RoundHasFinalized{} | ||
} | ||
|
||
// TestCase implements TestCaseConfigurator interface. | ||
func (n *RoundHasFinalized) TestCase() cases.TestCase { | ||
return cases.NewRoundHasFinalized() | ||
} | ||
|
||
// Name implements TestCaseConfigurator interface. | ||
func (n *RoundHasFinalized) Name() string { | ||
return RoundHasFinalizedName | ||
} | ||
|
||
// Decode implements MapDecoder interface. | ||
func (n *RoundHasFinalized) Decode(val interface{}) error { | ||
return mapstructure.Decode(val, n) | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.