Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
contrib
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blockchain
contrib
Commits
3b8b8bec
Commit
3b8b8bec
authored
6 years ago
by
Miguel Montes
Browse files
Options
Downloads
Patches
Plain Diff
Cambiada estructura para obtener status de sealers
Agregada la posibilidad de obtener timestamp del sellado de un bloque.
parent
942e35a9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bfa_client/src/bfa/node.go
+21
-12
21 additions, 12 deletions
bfa_client/src/bfa/node.go
bfa_client/src/client/bfa_client.go
+15
-4
15 additions, 4 deletions
bfa_client/src/client/bfa_client.go
with
36 additions
and
16 deletions
bfa_client/src/bfa/node.go
+
21
−
12
View file @
3b8b8bec
...
...
@@ -44,6 +44,11 @@ type SealerInfo struct {
LastBlock
int64
}
type
SealerStatus
struct
{
LastBlock
int64
`json:"lastBlockSigned"`
Time
uint64
`json:"timestamp"`
}
const
(
Latest
=
"latest"
Self
=
"self"
...
...
@@ -60,12 +65,15 @@ func (node *Node) blockNumber() int64 {
}
func
(
node
*
Node
)
Coinbase
()
(
coinbase
string
,
err
error
)
{
defer
func
(){
defer
func
()
{
if
e
:=
recover
();
e
!=
nil
{
switch
s
:=
e
.
(
type
){
case
string
:
err
=
fmt
.
Errorf
(
s
)
case
error
:
err
=
s
default
:
err
=
fmt
.
Errorf
(
"unknown error while getting coinbase: %v"
,
e
)
switch
s
:=
e
.
(
type
)
{
case
string
:
err
=
fmt
.
Errorf
(
s
)
case
error
:
err
=
s
default
:
err
=
fmt
.
Errorf
(
"unknown error while getting coinbase: %v"
,
e
)
}
}
}()
...
...
@@ -199,13 +207,13 @@ func (node *Node) GetVotes(blockNumber int64) (votes Proposals) {
return
}
func
(
node
*
Node
)
SealersStatus
(
blockNumber
int64
)
(
status
map
[
string
]
int64
)
{
func
(
node
*
Node
)
SealersStatus
(
blockNumber
int64
)
(
status
map
[
string
]
*
SealerStatus
)
{
if
blockNumber
==
0
{
// Genesis block doesn't have signer
return
}
status
=
make
(
map
[
string
]
int64
)
status
=
make
(
map
[
string
]
*
SealerStatus
)
for
_
,
address
:=
range
node
.
GetSignersAtBlock
(
blockNumber
)
{
status
[
address
]
=
-
1
status
[
address
]
=
&
SealerStatus
{}
}
notSeen
:=
int64
(
len
(
status
))
block
:=
node
.
GetBlockByNumber
(
blockNumber
)
...
...
@@ -213,8 +221,9 @@ func (node *Node) SealersStatus(blockNumber int64) (status map[string]int64) {
until
:=
Max
(
1
,
blockNumber
-
5
*
notSeen
)
for
notSeen
>
0
{
signer
,
_
:=
GetSigner
(
&
block
)
if
status
[
signer
]
==
-
1
{
status
[
signer
]
=
block
.
Number
.
Int64
()
if
status
[
signer
]
.
LastBlock
==
0
{
status
[
signer
]
.
LastBlock
=
block
.
Number
.
Int64
()
status
[
signer
]
.
Time
=
block
.
Time
.
Uint64
()
notSeen
--
}
if
blockNumber
==
until
{
...
...
@@ -295,7 +304,7 @@ func (node *Node) getSignerFirstBlock(signer string, since int64, until int64) (
case
found
:=
<-
ch
:
switch
{
case
found
<
0
:
n
--
// a goroutine has ended
n
--
// a goroutine has ended
if
n
==
0
{
// all goroutines have ended
return
}
...
...
@@ -359,7 +368,7 @@ func (node *Node) getSignerLastBlock(signer string, since int64, until int64) (b
case
found
:=
<-
ch
:
switch
{
case
found
<
0
:
n
--
// a goroutine has ended
n
--
// a goroutine has ended
if
n
==
0
{
// all goroutines have ended
return
}
...
...
This diff is collapsed.
Click to expand it.
bfa_client/src/client/bfa_client.go
+
15
−
4
View file @
3b8b8bec
...
...
@@ -106,11 +106,14 @@ func sealers() {
var
(
blockNumber
int64
status
bool
timestamp
bool
length
int64
=
10
// timestamp length
)
description
=
"Presenta la lista de selladores. Opcionalmente indica el último bloque sellado por cada uno."
setFlags
()
flags
.
Int64Var
(
&
blockNumber
,
"block-number"
,
latest
,
"Número del bloque en el cual se quiere conocer la lista de selladores (-1 para el último)"
)
flags
.
BoolVar
(
&
status
,
"status"
,
false
,
"Indica el último bloque sellado por cada sellador, o -1 si un nodo no ha sellado en las últimas 5 rondas."
)
flags
.
BoolVar
(
&
status
,
"status"
,
false
,
"Indica el último bloque sellado por cada sellador, o 0 si un nodo no ha sellado en las últimas 5 rondas."
)
flags
.
BoolVar
(
&
timestamp
,
"timestamp"
,
false
,
"Muestra el timestamp del sellado en lugar del número de bloque."
)
parseFlags
()
if
blockNumber
==
0
{
panic
(
"El bloque génesis no tiene firmantes"
)
...
...
@@ -129,10 +132,18 @@ func sealers() {
for
sealer
:=
range
sealers
{
list
=
append
(
list
,
sealer
)
}
sort
.
Slice
(
list
,
func
(
i
,
j
int
)
bool
{
return
sealers
[
list
[
i
]]
>
sealers
[
list
[
j
]]
})
length
:=
util
.
Max
(
2
,
int64
(
len
(
strconv
.
FormatInt
(
sealers
[
list
[
0
]],
10
))))
sort
.
Slice
(
list
,
func
(
i
,
j
int
)
bool
{
return
sealers
[
list
[
i
]]
.
LastBlock
>
sealers
[
list
[
j
]]
.
LastBlock
})
if
!
timestamp
{
length
=
util
.
Max
(
2
,
int64
(
len
(
strconv
.
FormatInt
(
sealers
[
list
[
0
]]
.
LastBlock
,
10
))))
}
for
_
,
sealer
:=
range
list
{
fmt
.
Printf
(
"%v: %*d
\n
"
,
sealer
,
length
,
sealers
[
sealer
])
var
output
interface
{}
if
timestamp
{
output
=
sealers
[
sealer
]
.
Time
}
else
{
output
=
sealers
[
sealer
]
.
LastBlock
}
fmt
.
Printf
(
"%v: %*d
\n
"
,
sealer
,
length
,
output
)
}
}
else
{
sealers
:=
node
.
GetSignersAtBlock
(
blockNumber
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment