Skip to content
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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Conversation

BartoszZabuski
Copy link

No description provided.

@@ -21,6 +21,10 @@ import (
"gopkg.in/mgo.v2/bson"
)

const (
Copy link
Member

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.

Copy link
Author

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

fmt.Println("user validated!")

// validate validator exists & update votes
validatorID := bson.ObjectIdHex(entity["validator"].(string))
Copy link
Member

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.

Copy link
Author

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

Copy link
Author

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

// 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 {
Copy link
Member

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?

Copy link
Author

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.

Copy link
Author

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.

// that could be considered an issue depending on requirements
project := bson.M{
"$project": bson.M{
"name": 1,
Copy link
Member

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.

Copy link
Author

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

Copy link
Author

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"))
Copy link
Member

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?

Copy link
Author

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 ;) )

Copy link
Author

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

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"`
Copy link
Member

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.

Copy link
Author

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

if validators != nil {
for _, element := range validators {
validator := Validator{
ID: bson.NewObjectId(),
Copy link
Author

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.

Bartosz Zabuski and others added 4 commits August 3, 2018 04:16
…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…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants