Error when adding data to preordered log
gremlin97 opened this issue · comments
- Hi, I had a created a Preordered log with the command:
go run github.com/google/trillian/cmd/createtree --admin_server=localhost:8090 \ --tree_type=PREORDERED_LOG
- When using AddsequencedLeaf to add data to the log I get an error:
rpc error: code = InvalidArgument desc = operation not allowed for LOG-type trees (wanted one of map[PREORDERED_LOG:true]) exit status 1
- However, when I use QueueLeafRequest I am able to add data to the leaf. Can you please help me to resolve this error. Thanks!
package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"log"
"github.com/google/trillian"
"google.golang.org/grpc"
)
type trillianLogClient struct {
client trillian.TrillianLogClient
logID int64
}
var (
tLogEndpoint = flag.String("tlog_endpoint", ":8090", "The gRPC endpoint of the Trillian Log Server.")
tPlogID = flag.Int64("tplog_id", 862641119046779663, "Trillian Preordered Log ID")
)
type Address struct {
category string
mode string
time string
day string
number int64
}
func main() {
flag.Parse() //parses input from terminal
conn, err := grpc.Dial(*tLogEndpoint, grpc.WithInsecure())
if err != nil {
log.Fatal(err)
}
defer conn.Close()
tclient := trillian.NewTrillianLogClient(conn)
tLogClient := &trillianLogClient{client: tclient, logID: *tPlogID}
in := Address{"3", "4", "5", "5", 904487}
index := in.number
fmt.Println("Number = ", index)
//Converting to bytes
leafVal, err := json.Marshal(in)
//leave struct
leaf := &trillian.LogLeaf{
LeafValue: leafVal,
LeafIndex: index,
}
//request struct
leafreq := &trillian.AddSequencedLeafRequest{
LogId: *tPlogID,
Leaf: leaf,
}
//Sending request to trillian to append data
leafresp, err := tLogClient.client.AddSequencedLeaf(context.Background(), leafreq)
if err != nil {
log.Fatal(err)
}
fmt.Println("Leafresp", leafresp)
}
Above code snippet is giving the given error
Hi,
The error you're getting says the tree has the wrong type. It should be PREORDERED_LOG
. The createtree
command defaults to LOG
so you'll need to pass the --tree_type
flag to it.
Wait I saw you did set that flag. Can you list the trees with the admin API and check what type it has?
I am using docker-containers for trillian servers
That shows the tree as type LOG
, which is incorrect. Can you create one via the admin API and see what it shows.
Thank you! The issue is solved. There was a problem while creating the log which was corrected by using the Admin API!