Commit e9ad121a authored by Srinivasan Muralidharan's avatar Srinivasan Muralidharan
Browse files

FAB-853 remove ledger and move ledgernext to ledger



FAB-853

Ledger is removed from
   . core/peer/peer.go
   . core/rest/api.go

Ledger package itself is removed. "ledgernext" is
replaced with "ledger".

Change-Id: Ie7dfbd9bf94afa0031aef759fc46929e4fb3b400
Signed-off-by: default avatarSrinivasan Muralidharan <muralisr@us.ibm.com>
parent 0157a51a
......@@ -21,7 +21,6 @@ import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/chaincode/shim"
ld "github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/protos"
)
......@@ -40,10 +39,6 @@ type SystemChaincode struct {
func (t *SystemChaincode) getLedger() ledgerHandler {
if t.mockLedgerH == nil {
lh, err := ld.GetLedger()
if err == nil {
return lh
}
panic("Chaincode is unable to get the ledger.")
} else {
return t.mockLedgerH
......
......@@ -34,7 +34,7 @@ import (
"github.com/hyperledger/fabric/core/container"
"github.com/hyperledger/fabric/core/container/ccintf"
"github.com/hyperledger/fabric/core/crypto"
ledgernext "github.com/hyperledger/fabric/core/ledgernext"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/flogging"
pb "github.com/hyperledger/fabric/protos"
)
......@@ -64,8 +64,8 @@ func init() {
}
//use this for ledger access and make sure TXSimulator is being used
func getTxSimulator(context context.Context) ledgernext.TxSimulator {
if txsim, ok := context.Value(TXSimulatorKey).(ledgernext.TxSimulator); ok {
func getTxSimulator(context context.Context) ledger.TxSimulator {
if txsim, ok := context.Value(TXSimulatorKey).(ledger.TxSimulator); ok {
return txsim
}
panic("!!!---Not Using ledgernext---!!!")
......
......@@ -31,8 +31,8 @@ import (
"github.com/hyperledger/fabric/core/container"
"github.com/hyperledger/fabric/core/container/ccintf"
"github.com/hyperledger/fabric/core/crypto"
ledgernext "github.com/hyperledger/fabric/core/ledgernext"
"github.com/hyperledger/fabric/core/ledgernext/kvledger"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/kvledger"
"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/membersrvc/ca"
pb "github.com/hyperledger/fabric/protos"
......@@ -154,7 +154,7 @@ func finitPeer(lis net.Listener) {
os.RemoveAll(filepath.Join(os.TempDir(), "hyperledger"))
}
func startTxSimulation(ctxt context.Context) (context.Context, ledgernext.TxSimulator, error) {
func startTxSimulation(ctxt context.Context) (context.Context, ledger.TxSimulator, error) {
ledgername := string(DefaultChain)
lgr := kvledger.GetLedger(ledgername)
txsim, err := lgr.NewTxSimulator()
......@@ -166,7 +166,7 @@ func startTxSimulation(ctxt context.Context) (context.Context, ledgernext.TxSimu
return ctxt, txsim, nil
}
func endTxSimulation(txsim ledgernext.TxSimulator, payload []byte, commit bool) error {
func endTxSimulation(txsim ledger.TxSimulator, payload []byte, commit bool) error {
txsim.Done()
ledgername := string(DefaultChain)
if lgr := kvledger.GetLedger(ledgername); lgr != nil {
......@@ -361,7 +361,7 @@ func invoke(ctx context.Context, spec *pb.ChaincodeSpec) (ccevt *pb.ChaincodeEve
return nil, uuid, nil, fmt.Errorf("Error invoking chaincode: %s ", err)
}
var txsim ledgernext.TxSimulator
var txsim ledger.TxSimulator
ctx, txsim, err = startTxSimulation(ctx)
if err != nil {
return nil, uuid, nil, fmt.Errorf("Failed to get handle to simulator: %s ", err)
......@@ -1120,7 +1120,7 @@ func TestChaincodeQueryChaincodeWithSec(t *testing.T) {
// Test the invocation of a transaction.
func TestRangeQuery(t *testing.T) {
//TODO enable after ledgernext enables RangeQuery
//TODO enable after ledger enables RangeQuery
t.Skip()
lis, err := initPeer()
......
......@@ -25,7 +25,7 @@ import (
"github.com/golang/protobuf/proto"
ccintf "github.com/hyperledger/fabric/core/container/ccintf"
"github.com/hyperledger/fabric/core/crypto"
ledgernext "github.com/hyperledger/fabric/core/ledgernext"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/util"
pb "github.com/hyperledger/fabric/protos"
"github.com/looplab/fsm"
......@@ -58,9 +58,9 @@ type transactionContext struct {
responseNotifier chan *pb.ChaincodeMessage
// tracks open iterators used for range queries
rangeQueryIteratorMap map[string]ledgernext.ResultsIterator
rangeQueryIteratorMap map[string]ledger.ResultsIterator
txsimulator ledgernext.TxSimulator
txsimulator ledger.TxSimulator
}
type nextStateInfo struct {
......@@ -123,7 +123,7 @@ func (handler *Handler) createTxContext(ctxt context.Context, txid string, tx *p
return nil, fmt.Errorf("txid:%s exists", txid)
}
txctx := &transactionContext{transactionSecContext: tx, responseNotifier: make(chan *pb.ChaincodeMessage, 1),
rangeQueryIteratorMap: make(map[string]ledgernext.ResultsIterator)}
rangeQueryIteratorMap: make(map[string]ledger.ResultsIterator)}
handler.txCtxs[txid] = txctx
txctx.txsimulator = getTxSimulator(ctxt)
......@@ -145,13 +145,13 @@ func (handler *Handler) deleteTxContext(txid string) {
}
func (handler *Handler) putRangeQueryIterator(txContext *transactionContext, txid string,
rangeScanIterator ledgernext.ResultsIterator) {
rangeScanIterator ledger.ResultsIterator) {
handler.Lock()
defer handler.Unlock()
txContext.rangeQueryIteratorMap[txid] = rangeScanIterator
}
func (handler *Handler) getRangeQueryIterator(txContext *transactionContext, txid string) ledgernext.ResultsIterator {
func (handler *Handler) getRangeQueryIterator(txContext *transactionContext, txid string) ledger.ResultsIterator {
handler.Lock()
defer handler.Unlock()
return txContext.rangeQueryIteratorMap[txid]
......@@ -727,7 +727,7 @@ func (handler *Handler) handleRangeQueryState(msg *pb.ChaincodeMessage) {
return
}
//PDMP - let it panic if not KV
kv := qresult.(ledgernext.KV)
kv := qresult.(ledger.KV)
// Decrypt the data if the confidential is enabled
decryptedValue, decryptErr := handler.decrypt(msg.Txid, kv.Value)
if decryptErr != nil {
......@@ -835,7 +835,7 @@ func (handler *Handler) handleRangeQueryStateNext(msg *pb.ChaincodeMessage) {
return
}
//PDMP - let it panic if not KV
kv := qresult.(ledgernext.KV)
kv := qresult.(ledger.KV)
// Decrypt the data if the confidential is enabled
decryptedValue, decryptErr := handler.decrypt(msg.Txid, kv.Value)
if decryptErr != nil {
......
......@@ -18,20 +18,12 @@ package chaincode
import (
//import system chain codes here
"github.com/hyperledger/fabric/bddtests/syschaincode/noop"
"github.com/hyperledger/fabric/core/system_chaincode/escc"
"github.com/hyperledger/fabric/core/system_chaincode/vscc"
)
//see systemchaincode_test.go for an example using "sample_syscc"
var systemChaincodes = []*SystemChaincode{
{
Enabled: true,
Name: "noop",
Path: "github.com/hyperledger/fabric/bddtests/syschaincode/noop",
InitArgs: [][]byte{},
Chaincode: &noop.SystemChaincode{},
},
{
Enabled: true,
Name: "lccc",
......
......@@ -21,8 +21,8 @@ import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/chaincode/shim"
ledger "github.com/hyperledger/fabric/core/ledgernext"
"github.com/hyperledger/fabric/core/ledgernext/kvledger"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/kvledger"
pb "github.com/hyperledger/fabric/protos"
"github.com/op/go-logging"
"golang.org/x/net/context"
......
......@@ -23,8 +23,8 @@ import (
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/core/container/inproccontroller"
ledgernext "github.com/hyperledger/fabric/core/ledgernext"
"github.com/hyperledger/fabric/core/ledgernext/kvledger"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/kvledger"
"github.com/hyperledger/fabric/protos"
"github.com/op/go-logging"
"github.com/spf13/viper"
......@@ -80,7 +80,7 @@ func RegisterSysCC(syscc *SystemChaincode) error {
chainName := string(DefaultChain)
lgr := kvledger.GetLedger(chainName)
var txsim ledgernext.TxSimulator
var txsim ledger.TxSimulator
if txsim, err = lgr.NewTxSimulator(); err != nil {
return err
}
......
......@@ -21,7 +21,7 @@ import (
"testing"
"time"
"github.com/hyperledger/fabric/core/ledgernext/kvledger"
"github.com/hyperledger/fabric/core/ledger/kvledger"
"github.com/hyperledger/fabric/core/system_chaincode/samplesyscc"
"github.com/hyperledger/fabric/core/util"
pb "github.com/hyperledger/fabric/protos"
......
......@@ -26,7 +26,7 @@ import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/chaincode"
"github.com/hyperledger/fabric/core/committer"
"github.com/hyperledger/fabric/core/ledgernext/kvledger"
"github.com/hyperledger/fabric/core/ledger/kvledger"
ab "github.com/hyperledger/fabric/orderer/atomicbroadcast"
"golang.org/x/net/context"
"google.golang.org/grpc"
......
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package crypto
import (
"errors"
"strconv"
"time"
"github.com/spf13/viper"
"github.com/hyperledger/fabric/core/crypto/primitives"
"github.com/hyperledger/fabric/core/ledger"
obc "github.com/hyperledger/fabric/protos"
)
//We are temporarily disabling the validity period functionality
var allowValidityPeriodVerification = false
func validityPeriodVerificationEnabled() bool {
// If the verification of the validity period is enabled in the configuration file return the configured value
if viper.IsSet("peer.validator.validity-period.verification") {
return viper.GetBool("peer.validator.validity-period.verification")
}
// Validity period verification is enabled by default if no configuration was specified.
return true
}
func (validator *validatorImpl) verifyValidityPeriod(tx *obc.Transaction) (*obc.Transaction, error) {
if tx.Cert != nil && tx.Signature != nil {
// Unmarshal cert
cert, err := primitives.DERToX509Certificate(tx.Cert)
if err != nil {
validator.Errorf("verifyValidityPeriod: failed unmarshalling cert %s:", err)
return tx, err
}
cid := viper.GetString("pki.validity-period.chaincodeHash")
ledger, err := ledger.GetLedger()
if err != nil {
validator.Errorf("verifyValidityPeriod: failed getting access to the ledger %s:", err)
return tx, err
}
vpBytes, err := ledger.GetState(cid, "system.validity.period", true)
if err != nil {
validator.Errorf("verifyValidityPeriod: failed reading validity period from the ledger %s:", err)
return tx, err
}
i, err := strconv.ParseInt(string(vpBytes[:]), 10, 64)
if err != nil {
validator.Errorf("verifyValidityPeriod: failed to parse validity period %s:", err)
return tx, err
}
vp := time.Unix(i, 0)
var errMsg string
// Verify the validity period of the TCert
switch {
case cert.NotAfter.Before(cert.NotBefore):
errMsg = "verifyValidityPeriod: certificate validity period is invalid"
case vp.Before(cert.NotBefore):
errMsg = "verifyValidityPeriod: certificate validity period is in the future"
case vp.After(cert.NotAfter):
errMsg = "verifyValidityPeriod: certificate validity period is in the past"
}
if errMsg != "" {
validator.Error(errMsg)
return tx, errors.New(errMsg)
}
}
return tx, nil
}
......@@ -24,8 +24,8 @@ import (
"golang.org/x/net/context"
"github.com/hyperledger/fabric/core/chaincode"
ledger "github.com/hyperledger/fabric/core/ledgernext"
"github.com/hyperledger/fabric/core/ledgernext/kvledger"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/kvledger"
"github.com/hyperledger/fabric/core/peer"
"github.com/hyperledger/fabric/core/util"
pb "github.com/hyperledger/fabric/protos"
......
......@@ -30,7 +30,7 @@ import (
"github.com/hyperledger/fabric/core/container"
"github.com/hyperledger/fabric/core/crypto"
"github.com/hyperledger/fabric/core/db"
"github.com/hyperledger/fabric/core/ledgernext/kvledger"
"github.com/hyperledger/fabric/core/ledger/kvledger"
u "github.com/hyperledger/fabric/core/util"
pb "github.com/hyperledger/fabric/protos"
"github.com/spf13/viper"
......
## Ledger Package
This package implements the ledger, which includes the blockchain and global state.
If you're looking for API to work with the blockchain or state, look in `ledger.go`. This is the file where all public functions are exposed and is extensively documented. The sections in the file are:
### Transaction-batch functions
These are functions that consensus should call. `BeginTxBatch` followed by `CommitTxBatch` or `RollbackTxBatch`. These functions will add a block to the blockchain with the specified transactions.
### World-state functions
These functions are used to modify the global state. They would generally be called by the VM based on requests from chaincode.
### Blockchain functions
These functions can be used to retrieve blocks/transactions from the blockchain or other information such as the blockchain size. Addition of blocks to the blockchain is done though the transaction-batch related functions.
#!/bin/bash
source ../common.sh
PKG_PATH="github.com/hyperledger/fabric/core/ledger/statemgmt/buckettree"
FUNCTION_NAME="BenchmarkStateHash"
NUM_CPUS=1
CHART_DATA_COLUMN="NUM EXISTING KEYS"
export PEER_LEDGER_TEST_LOADYAML=false
function runTest {
OUTPUT_DIR="$FUNCTION_NAME/${NumBuckets}_${KVSize}"
DB_DIR="$FUNCTION_NAME/${NumBuckets}_${KVSize}"
TEST_PARAMS="-NumBuckets=$NumBuckets,\
-MaxGroupingAtEachLevel=$MaxGroupingAtEachLevel,\
-ChaincodeIDPrefix=$ChaincodeIDPrefix,\
-NumChaincodes=$NumChaincodes,\
-MaxKeySuffix=$MaxKeySuffix,\
-NumKeysToInsert=$NumKeysToInsert,\
-KVSize=$KVSize"
setupAndCompileTest
for i in `seq 0 999`; do
EXISTING_KEYS_IN_DB=$(($i*$NumKeysToInsert))
echo "executing with existing keys=$EXISTING_KEYS_IN_DB"
CHART_COLUMN_VALUE=$EXISTING_KEYS_IN_DB
executeTest
done
ADDITIONAL_TEST_FLAGS="-test.cpuprofile=cpu.out -test.outputdir=`getOuputDir`"
CHART_COLUMN_VALUE=$(($(($i+1))*$NumKeysToInsert))
executeTest
constructChart
}
##### TEST PARAMS
MaxGroupingAtEachLevel=5
ChaincodeIDPrefix="chaincode"
NumChaincodes=5
MaxKeySuffix=1000000
NumKeysToInsert=1000
NumBuckets=1009;KVSize=20;runTest
NumBuckets=10009;KVSize=20;runTest
NumBuckets=100003;KVSize=20;runTest
NumBuckets=1000003;KVSize=20;runTest
NumBuckets=1009;KVSize=50;runTest
NumBuckets=10009;KVSize=50;runTest
NumBuckets=100003;KVSize=50;runTest
NumBuckets=1000003;KVSize=50;runTest
NumBuckets=1009;KVSize=100;runTest
NumBuckets=10009;KVSize=100;runTest
NumBuckets=100003;KVSize=100;runTest
NumBuckets=1000003;KVSize=100;runTest
NumBuckets=1009;KVSize=300;runTest
NumBuckets=10009;KVSize=300;runTest
NumBuckets=100003;KVSize=300;runTest
NumBuckets=1000003;KVSize=300;runTest
NumBuckets=1009;KVSize=500;runTest
NumBuckets=10009;KVSize=500;runTest
NumBuckets=100003;KVSize=500;runTest
NumBuckets=1000003;KVSize=500;runTest
NumBuckets=1009;KVSize=1000;runTest
NumBuckets=10009;KVSize=1000;runTest
NumBuckets=100003;KVSize=1000;runTest
NumBuckets=1000003;KVSize=1000;runTest
NumBuckets=1009;KVSize=2000;runTest
NumBuckets=10009;KVSize=2000;runTest
NumBuckets=100003;KVSize=2000;runTest
NumBuckets=1000003;KVSize=2000;runTest
NumBuckets=1009;KVSize=5000;runTest
NumBuckets=10009;KVSize=5000;runTest
NumBuckets=100003;KVSize=5000;runTest
NumBuckets=1000003;KVSize=5000;runTest
#!/usr/local/bin/gnuplot
reset
# Chart specific settings
set ylabel "milli second"
set xlabel "Existing Data"
set title "Buckettree performance"
# General settings
set key reverse Left outside
set grid
set terminal postscript dashed color
set style data linespoints
# plot command
plot dataFile using 1:($2/1000000) title "time taken"
#!/usr/local/bin/gnuplot
reset
# Chart specific settings
set ylabel "milli second"
set xlabel "Approx number of existing keys"
set title "Buckettree performance"
# General settings
#set key bottom center outside reverse box
set key left top reverse box Left
set key spacing 1 font ",9"
set grid
set terminal postscript enhanced color
#set style data linespoints
set style data lines
# plot command
plot '../output1/chart.dat' using 1:($2/1000000) title "NumBuckets=10009, MaxGroupingAtEachLevel=5, ValueSize=1000", \
'../output2/chart.dat' using 1:($2/1000000) title "NumBuckets=10009, MaxGroupingAtEachLevel=5, ValueSize=100", \
'../output3/chart.dat' using 1:($2/1000000) title "NumBuckets=10009, MaxGroupingAtEachLevel=5, ValueSize=10", \
'../output5/chart.dat' using 1:($2/1000000) title "NumBuckets=100003, MaxGroupingAtEachLevel=5, ValueSize=1000", \
'../output4/chart.dat' using 1:($2/1000000) title "NumBuckets=1000003,MaxGroupingAtEachLevel=5, ValueSize=1000", \
'../output8/chart.dat' using 1:($2/1000000) title "NumBuckets=1000003,MaxGroupingAtEachLevel=5, ValueSize=10"
#!/bin/bash
set -e
OUTPUT_DIR_ROOT=`echo ~/obc_perf/output`
DB_DIR_ROOT=`echo ~/obc_perf/db`
BINARY_DIR=`echo ~/obc_perf/bin`
mkdir -p $OUTPUT_DIR_ROOT
mkdir -p $DB_DIR_ROOT
mkdir -p $BINARY_DIR
BENCHMARK_OUTPUT_FILE="benchmark.out"
CHART_DATA_FILE="chart.dat"
CHART_FILE="chart.ps"
regex="^Benchmark.*[[:blank:]]+[[:digit:]]+[[:blank:]]+([[:digit:]]+).*$"
function writeBenchmarkOutput {
#echo "$@"
outFile=$1
benchmarkFile=$2
paramValue=$3
cmdOutput=$4
echo "outFile=$outFile, benchmarkFile=$benchmarkFile, paramValue=$paramValue"
echo "Test Output Start:"
echo "$cmdOutput"
echo "Test Output Finish"
while read -r line; do
echo $line >> $outFile
if [[ $line =~ $regex ]]; then
benchmarkDataLine="$paramValue ${BASH_REMATCH[1]}"
echo $benchmarkDataLine >> $benchmarkFile
fi
done <<< "$cmdOutput"
}
function setupAndCompileTest {
createOutputDir
configureDBPath
compileTest
writeBenchmarkHeader
}
function compileTest {
cmd="go test $PKG_PATH -c -o `getBinaryFileName`"
`eval $cmd`
}
function writeBenchmarkHeader {
outputDir=`getOuputDir`
echo "# `date`" >> $outputDir/$CHART_DATA_FILE
echo "# TEST_PARAMS $TEST_PARAMS" >> $outputDir/$CHART_DATA_FILE
echo "# $CHART_DATA_COLUMN | ns/ops" >> $outputDir/$CHART_DATA_FILE
}
## Execute test and generate data file
function executeTest {
cmd="`getBinaryFileName` -testParams=\"$TEST_PARAMS\" -test.run=XXX -test.bench=$FUNCTION_NAME -test.cpu=$NUM_CPUS $ADDITIONAL_TEST_FLAGS $PKG_PATH"
outputDir=`getOuputDir`
dbDir=`getDBDir`
echo ""
echo "Executing test... [OUTPUT_DIR=$outputDir, DB_DIR=$dbDir]"
echo $cmd
cmdOutput=`eval $cmd`
writeBenchmarkOutput $outputDir/$BENCHMARK_OUTPUT_FILE $outputDir/$CHART_DATA_FILE $CHART_COLUMN_VALUE "$cmdOutput"
}
function getBinaryFileName {
pkgName=$(basename $PKG_PATH)
echo "$BINARY_DIR/$pkgName.test"
}
function getOuputDir {
pkgName=$(basename $PKG_PATH)
outputDir="$OUTPUT_DIR_ROOT/$pkgName/$FUNCTION_NAME"
if [ ! -z "$OUTPUT_DIR" ]; then
outputDir="$OUTPUT_DIR_ROOT/$pkgName/$OUTPUT_DIR"
fi
echo $outputDir
}
function getDBDir {
pkgName=$(basename $PKG_PATH)
dbDir="$DB_DIR_ROOT/$pkgName/$FUNCTION_NAME"
if [ ! -z "$DB_DIR" ]; then
dbDir="$DB_DIR_ROOT/$pkgName/$DB_DIR"
fi
echo $dbDir
}
function createOutputDir {
outputDir=`getOuputDir`
if [ ! -d "$outputDir" ]; then
mkdir -p $outputDir
else
echo "INFO: outputDIR [$outputDir] already exists. Output will be appended to existing file"
fi
}
function configureDBPath {
dbDir=`getDBDir`
if [ -d "$dbDir" ]; then
echo "INFO: dbDir [$dbDir] already exists. Data will be merged in the existing data"
fi
ulimit -n 10000
echo "setting ulimit=`ulimit -n`"
export PEER_FILESYSTEMPATH="$dbDir"
}
function constructChart {
outputDir=`getOuputDir`
gnuplot -e "dataFile='$outputDir/$CHART_DATA_FILE'" plot.pg > $outputDir/$CHART_FILE
}
function openChart {
outputDir=`getOuputDir`
open "$outputDir/$CHART_FILE"
}
function clearOSCache {
platform=`uname`
if [[ $platform == 'Darwin' ]]; then
echo "Clearing os cache"