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

Change parameters for bor producer selection algorithm #1208

Merged
merged 30 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6e69da3
bor,helper: update seed and voting powers for producer selection
Raneet10 Oct 10, 2024
8dd9307
bor: minor fixes
Raneet10 Oct 15, 2024
e5db722
bor: fix GetNextSpanSeed for span-id<2
Raneet10 Oct 15, 2024
faa4719
helper: (temp) set HF height for testing
Raneet10 Oct 16, 2024
3a5d855
bor: (temp) change default params
Raneet10 Oct 16, 2024
fe5611e
bor: add logs + fix query for next span
Raneet10 Oct 16, 2024
518fa70
bor: modify last sprint producer case
Raneet10 Oct 17, 2024
fb2a910
bor: (temp) add logs for debugging
Raneet10 Oct 17, 2024
231a705
bor,helper: modify approach to get seed
Raneet10 Oct 21, 2024
dbe2e87
bor: some cleanup
Raneet10 Oct 21, 2024
571cfbb
bor: use pointer receivers + add some debug logs
Raneet10 Oct 22, 2024
7b1d107
bor,common: fix storage of seed producer
Raneet10 Oct 23, 2024
39af109
app,bor,helper: add UTs
Raneet10 Oct 25, 2024
d2235e5
Reduce validators collusion chance
avalkov Nov 6, 2024
cbb61bb
Additional tests
avalkov Nov 7, 2024
6453ee9
If no unique author found, return first one that is different from la…
avalkov Nov 11, 2024
58cfa9f
Change settings for testing
avalkov Nov 12, 2024
6af852f
Prevent taking seed in two consecutive spans from same author when th…
avalkov Nov 13, 2024
ce5e16c
Enable at zero height for testing
avalkov Nov 14, 2024
5c2a96a
Add more logging
avalkov Nov 14, 2024
dced711
When proposing span 1, take block 1
avalkov Nov 14, 2024
bb33ab6
Test for proposing span 1
avalkov Nov 14, 2024
6122af3
Fix tests
avalkov Nov 18, 2024
a2847a9
Refactor
avalkov Nov 18, 2024
173bd22
Update params
avalkov Nov 19, 2024
c714a90
bor,helper: address TODOs
Raneet10 Nov 20, 2024
e78e247
bor: add comments for getBorBlockForSpanSeed
Raneet10 Nov 26, 2024
8129b5e
helper: (temp) set HF height for testing
Raneet10 Nov 26, 2024
e51f401
bor,helper: set HF name and height for amoy and minor error logging c…
Raneet10 Nov 27, 2024
044bf85
bor: fix lint
Raneet10 Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func NewHeimdallApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.Ba
common.DefaultCodespace,
app.ChainKeeper,
app.StakingKeeper,
app.caller,
&app.caller,
)

app.ClerkKeeper = clerk.NewKeeper(
Expand Down
35 changes: 31 additions & 4 deletions bor/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,28 @@ func GetSpanList(cdc *codec.Codec) *cobra.Command {

// GetNextSpanSeed implements the next span seed.
func GetNextSpanSeed(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: "next-span-seed",
Args: cobra.NoArgs,
Short: "show the next span seed",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), nil)
spanIDStr := viper.GetString(FlagSpanId)
if spanIDStr == "" {
return fmt.Errorf("span id cannot be empty")
}

spanID, err := strconv.ParseUint(spanIDStr, 10, 64)
if err != nil {
return err
}

seedQueryParams, err := cliCtx.Codec.MarshalJSON(types.NewQuerySpanParams(spanID))
if err != nil {
return err
}

res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), seedQueryParams)
if err != nil {

fmt.Println("Error while fetching the span seed")
Expand All @@ -247,6 +261,14 @@ func GetNextSpanSeed(cdc *codec.Codec) *cobra.Command {

},
}

cmd.Flags().String(FlagSpanId, "", "--span-id=<span-id>")

if err := cmd.MarkFlagRequired(FlagSpanId); err != nil {
cliLogger.Error("GetNextSpanSeed | MarkFlagRequired | FlagSpanId", "Error", err)
}

return cmd
}

// PostSendProposeSpanTx send propose span transaction
Expand Down Expand Up @@ -309,7 +331,12 @@ func GetPreparedProposeSpan(cdc *codec.Codec) *cobra.Command {
return err
}

res, _, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), nil)
seedQueryParams, err := cliCtx.Codec.MarshalJSON(types.NewQuerySpanParams(spanID))
if err != nil {
return err
}

res, _, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), seedQueryParams)
if err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion bor/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ func PostSendProposeSpanTx(cdc *codec.Codec) *cobra.Command {
return err
}

res, _, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), nil)
seedQueryParams, err := cliCtx.Codec.MarshalJSON(types.NewQuerySpanParams(spanID))
if err != nil {
return err
}

res, _, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), seedQueryParams)
if err != nil {
return err
}
Expand Down
40 changes: 35 additions & 5 deletions bor/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,21 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc("/bor/span/{id}", spanHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/bor/latest-span", latestSpanHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/bor/prepare-next-span", prepareNextSpanHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/bor/next-span-seed", fetchNextSpanSeedHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/bor/next-span-seed/{id}", fetchNextSpanSeedHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/bor/params", paramsHandlerFn(cliCtx)).Methods("GET")
}

// swagger:route GET /bor/next-span-seed bor borNextSpanSeed
//swagger:parameters borCurrentSpanById
type borCurrentSpanById struct {

//Id number of the span
//required:true
//type:integer
//in:path
Id int `json:"id"`
}

// swagger:route GET /bor/next-span-seed/{id} bor borCurrentSpanById
// It returns the seed for the next span
// responses:
// 200: borNextSpanSeedResponse
Expand All @@ -153,7 +163,19 @@ func fetchNextSpanSeedHandlerFn(
return
}

res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), nil)
vars := mux.Vars(r)

spanID, ok := rest.ParseUint64OrReturnBadRequest(w, vars["id"])
if !ok {
return
}

seedQueryParams, err := cliCtx.Codec.MarshalJSON(types.NewQuerySpanParams(spanID))
if err != nil {
return
}

res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), seedQueryParams)
if err != nil {
RestLogger.Error("Error while fetching next span seed ", "Error", err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
Expand All @@ -165,7 +187,7 @@ func fetchNextSpanSeedHandlerFn(

// error if span seed found
if !hmRest.ReturnNotFoundIfNoContent(w, res, "NextSpanSeed not found") {
RestLogger.Error("NextSpanSeed not found ", "Error", err.Error())
RestLogger.Error("NextSpanSeed not found ", "Error", err)
return
}

Expand Down Expand Up @@ -458,8 +480,16 @@ func prepareNextSpanHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
// Fetching SelectedProducers
//

nextProducerBytes, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextProducers), nil)
query, err := cliCtx.Codec.MarshalJSON(types.NewQuerySpanParams(spanID))
if err != nil {
fmt.Println("error while marshalling: ", err)
hmRest.WriteErrorResponse(w, http.StatusNoContent, errors.New("unable to marshal JSON").Error())
return
}

nextProducerBytes, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextProducers), query)
if err != nil {
fmt.Println("error while querying next producers: ", err)
hmRest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
Expand Down
7 changes: 6 additions & 1 deletion bor/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,13 @@ func postProposeSpanHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return
}

seedQueryParams, err := cliCtx.Codec.MarshalJSON(types.NewQuerySpanParams(req.ID))
if err != nil {
return
}

// fetch seed
res, _, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), nil)
res, _, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), seedQueryParams)
if err != nil {
RestLogger.Error("Error while fetching next span seed ", "Error", err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
Expand Down
3 changes: 3 additions & 0 deletions bor/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package bor

var RollbackVotingPowers = rollbackVotingPowers
Loading
Loading