From 121f0d3fcf6224b46aa78ec8dc704fa224c2c9c3 Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Mon, 12 Mar 2018 14:43:15 -0700 Subject: [PATCH] types: compile time assert to, and document sort.Interface Fixes #212 Declare the purpose of the Less, Len, Swap methods so that readers can see why they are defined. Raised by an auditor in their report, as it looked like a security concern but actually sort.Interface requires those methods implemented. --- types/util.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/types/util.go b/types/util.go index 39a24e02..da5bc726 100644 --- a/types/util.go +++ b/types/util.go @@ -3,6 +3,7 @@ package types import ( "bytes" "encoding/json" + "sort" ) //------------------------------------------------------------------------------ @@ -10,6 +11,14 @@ import ( // Validators is a list of validators that implements the Sort interface type Validators []Validator +var _ sort.Interface = (Validators)(nil) + +// All these methods for Validators: +// Len, Less and Swap +// are for Validators to implement sort.Interface +// which will be used by the sort package. +// See Issue https://github.com/tendermint/abci/issues/212 + func (v Validators) Len() int { return len(v) }