Skip to content

Commit

Permalink
Add/conductor tests for blobber and validator (#1195)
Browse files Browse the repository at this point in the history
* Send WM commit status to conductor

* Rename file

* Modify log type

* Add state for stopping blobber from committing WM

* Log error

---------

Co-authored-by: Ebrahim Gomaa <[email protected]>
  • Loading branch information
lpoli and devyetii authored Aug 14, 2023
1 parent 3c08785 commit d302842
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 44 deletions.
2 changes: 1 addition & 1 deletion code/go/0chain.net/blobbercore/challenge/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (cr *ChallengeEntity) LoadValidationTickets(ctx context.Context) error {
resp, err := util.SendPostRequest(url, postDataBytes, nil)
if err != nil {
//network issue, don't cancel it, and try it again
logging.Logger.Info("[challenge]post: ", zap.Any("error", err.Error()))
logging.Logger.Error("[challenge]post: ", zap.Any("error", err.Error()))
updateMapAndSlice(validatorID, i, nil)
return
}
Expand Down
2 changes: 1 addition & 1 deletion code/go/0chain.net/blobbercore/writemarker/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (wme *WriteMarkerEntity) VerifyMarker(ctx context.Context, dbAllocation *al
return nil
}

func (wme *WriteMarkerEntity) RedeemMarker(ctx context.Context) error {
func (wme *WriteMarkerEntity) redeemMarker(ctx context.Context) error {
if len(wme.CloseTxnID) > 0 {
t, err := transaction.VerifyTransaction(wme.CloseTxnID, chain.GetServerChain())
if err == nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//go:build integration_tests
// +build integration_tests

package writemarker

import (
"context"
"time"

"github.com/0chain/blobber/code/go/0chain.net/conductor/conductrpc"
"github.com/0chain/blobber/code/go/0chain.net/core/node"
)

func (wme *WriteMarkerEntity) RedeemMarker(ctx context.Context) error {
for {
state := conductrpc.Client().State()
if state.StopWMCommit != nil && *state.StopWMCommit {
time.Sleep(time.Second * 5)
continue
}
break
}
err := wme.redeemMarker(ctx)
if err == nil {
// send state to conductor server
conductrpc.Client().BlobberCommitted(node.Self.ID)
}
return err
}
10 changes: 10 additions & 0 deletions code/go/0chain.net/blobbercore/writemarker/protocol_main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build !integration_tests
// +build !integration_tests

package writemarker

import "context"

func (wme *WriteMarkerEntity) RedeemMarker(ctx context.Context) error {
return wme.redeemMarker(ctx)
}
5 changes: 5 additions & 0 deletions code/go/0chain.net/conductor/conductrpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ func (c *client) state(me NodeID) (state *State, err error) {
}
return
}

func (c *client) blobberCommitted(blobberID string) (err error) {
err = c.client.Call("Server.BlobberCommitted", blobberID, nil)
return
}
28 changes: 17 additions & 11 deletions code/go/0chain.net/conductor/conductrpc/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ func (e *Entity) isMonitor() bool { //nolint:unused,deadcode // might be used la
return state != nil && state.IsMonitor
}

func (e *Entity) BlobberCommitted(blobberID string) {
err := e.client.blobberCommitted(blobberID)
if err != nil {
log.Println(err)
}
}

//
// global
//
Expand All @@ -120,17 +127,16 @@ func Shutdown() {

// Client returns global Entity to interact with. Use it, for example,
//
// var state = conductrpc.Client().State()
// for _, minerID := range miners {
// if state.VRFS.IsBad(state, minerID) {
// // send bad VRFS to this miner
// } else if state.VRFS.IsGood(state, minerID) {
// // send good VRFS to this miner
// } else {
// // don't send a VRFS to this miner
// }
// }
//
// var state = conductrpc.Client().State()
// for _, minerID := range miners {
// if state.VRFS.IsBad(state, minerID) {
// // send bad VRFS to this miner
// } else if state.VRFS.IsGood(state, minerID) {
// // send good VRFS to this miner
// } else {
// // don't send a VRFS to this miner
// }
// }
func Client() *Entity {
return global
}
34 changes: 3 additions & 31 deletions code/go/0chain.net/conductor/conductrpc/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,8 @@ type State struct {
// Nodes maps NodeID -> NodeName.
Nodes map[NodeID]NodeName

IsMonitor bool // send monitor events (round, phase, etc)
IsLock bool // node locked
IsRevealed bool // revealed shares
// Byzantine state. Below, if a value is nil, then node behaves as usual
// for it.
//
// Byzantine blockchain
VRFS *config.Bad
RoundTimeout *config.Bad
CompetingBlock *config.Bad
SignOnlyCompetingBlocks *config.Bad
DoubleSpendTransaction *config.Bad
WrongBlockSignHash *config.Bad
WrongBlockSignKey *config.Bad
WrongBlockHash *config.Bad
VerificationTicketGroup *config.Bad
WrongVerificationTicketHash *config.Bad
WrongVerificationTicketKey *config.Bad
WrongNotarizedBlockHash *config.Bad
WrongNotarizedBlockKey *config.Bad
NotarizeOnlyCompetingBlock *config.Bad
NotarizedBlock *config.Bad
// Byzantine blockchain sharders
FinalizedBlock *config.Bad
MagicBlock *config.Bad
VerifyTransaction *config.Bad
// Byzantine View Change
MPK *config.Bad
Shares *config.Bad
Signatures *config.Bad
Publish *config.Bad
IsMonitor bool // send monitor events (round, phase, etc)
IsLock bool // node locked

// Blobbers related states
StorageTree *config.Bad // blobber sends bad files/tree responses
Expand All @@ -91,6 +62,7 @@ type State struct {
BlobberUpload BlobberUpload
BlobberDelete BlobberDelete
AdversarialValidator AdversarialValidator
StopWMCommit *bool
}

// Name returns NodeName by given NodeID.
Expand Down

0 comments on commit d302842

Please sign in to comment.