-
Notifications
You must be signed in to change notification settings - Fork 27
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
DPOS example #2
base: master
Are you sure you want to change the base?
DPOS example #2
Conversation
@@ -21,6 +21,10 @@ import ( | |||
"gopkg.in/mgo.v2/bson" | |||
) | |||
|
|||
const ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we set it to at least 4
? so that we can test out the byzantine fault tolerance. Tendermint will continue to produce blocks as long as more than 2/3 of validators are non-malicious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes you are right, that was originally 4 but I've started decreasing it when I struggled to set up nodes locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
jsonstore/jsonstore.go
Outdated
fmt.Println("user validated!") | ||
|
||
// validate validator exists & update votes | ||
validatorID := bson.ObjectIdHex(entity["validator"].(string)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is also possible to retrieve validatorID via the publicKey
. This way you won't have to supply validatorID separately for voting from the front-end. Supplying just the publicKey
of the person will suffice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice. Didn't realise that. Make sense since NodeId is derived the same way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i got back to this comment now and realised it doesnt work for me.. let's discuss it in the morning
jsonstore/jsonstore.go
Outdated
// validate validator exists & update votes | ||
validatorID := bson.ObjectIdHex(entity["validator"].(string)) | ||
err = db.C("validators").Update(bson.M{"_id": validatorID}, bson.M{"$addToSet": bson.M{"votes": user.ID}}) | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are doing only $addToSet
here. What about the scenario when the user wants to retract the vote assigned to a particular person?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought of that but I didnt implement it as I wanted to test what I had first and was struggling with that at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added scenario to downvote validator.
jsonstore/jsonstore.go
Outdated
// that could be considered an issue depending on requirements | ||
project := bson.M{ | ||
"$project": bson.M{ | ||
"name": 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have to use aggregation if we just maintain another property called votes
(integer) in the validator documents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point. Could have added "increment" and new field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added vote count as a part of adding extra collection
mint.go
Outdated
@@ -22,14 +24,16 @@ func initJSONStore() error { | |||
// Create the application | |||
var app types.Application | |||
|
|||
session, err := mgo.Dial("localhost") | |||
fmt.Println("running aginst mongo: ", os.Getenv("MONGO_URL")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Mongo_URL
env is not set, what does it use by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it uses localhost:27017 but tbh its not obvious from the client library code... When I added it and run it just still worked which surprised me too. (unless there is another bug I missed ;) )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so turned out i was wrong and it doesn't default to localhost:27017.. must have forgotten i've added it. This way or the other im removing it as well as removing override for the ABCI port. Since you may be merging it there is no point in me forcing code basically added for testing
jsonstore/jsonstore.go
Outdated
ID bson.ObjectId `bson:"_id" json:"_id"` | ||
Name string `bson:"name" json:"name"` | ||
PublicKey []byte `bson:"publicKey" json:"publicKey"` | ||
Votes []bson.ObjectId `bson:"votes" json:"votes"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validator documents can quickly grow in size (MongoDB documents have a 16MB size limit) if we store the ObjectIDs of voters in the same document (Votes
array). There is no upper limit to the number of voters. I would suggest storing the votes
count in the document itself and move the ObjectIDs of voters to a separate junction collection. This will also help us sort the validators efficiently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed added UserValidatorVote collection
jsonstore/jsonstore.go
Outdated
if validators != nil { | ||
for _, element := range validators { | ||
validator := Validator{ | ||
ID: bson.NewObjectId(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a bug. We cannot generate random value for each like that cos it will create different IDs on on every validator node.
…ike Address, PubKey etc., adding code for testing
adding script to trigger multiple nodes locally
…ling upgrading tendermint to have proper access to Validators attributes l…
No description provided.